Question: Can you guys help me explain what is happening here.

```
$data[0] = array("one" => "uno", "two" => "dos", "three" => "tres");
$data[1] = array("one" => "uno", "two" => "dos", "three" => "tres");

//unset($data[0]);

$encode = json_encode($data);

$decode = json_decode($encode);

var_dump($decode);

```

outputs:

```
array(2) { [0]=> object(stdClass)#1 (3) { ["one"]=> string(3) "uno" ["two"]=> string(3) "dos" ["three"]=> string(4) "tres" } [1]=> object(stdClass)#2 (3) { ["one"]=> string(3) "uno" ["two"]=> string(3) "dos" ["three"]=> string(4) "tres" } }

```

This is normal keeps it as an array but as soon as I unset a part of the array it turns it into an obj.

```
$data[0] = array("one" => "uno", "two" => "dos", "three" => "tres");
$data[1] = array("one" => "uno", "two" => "dos", "three" => "tres");

unset($data[0]);

$encode = json_encode($data);

$decode = json_decode($encode);

var_dump($decode);

```

output:

```
object(stdClass)#1 (1) { ["1"]=> object(stdClass)#2 (3) { ["one"]=> string(3) "uno" ["two"]=> string(3) "dos" ["three"]=> string(4) "tres" } }

```

How do I keep the consistency?

Answer: 
I would look at [json\_encode](http://php.net/manual/en/function.json-encode.php) at the options. I think `JSON_FORCE_OBJECT` should force constancy.
Javascript distinguishes between arrays and objects. PHP only has arrays to cover both types at once.

*Continuously numerically 0-starting PHP arrays* are encoded to Javascript arrays, anything else is encoded to objects.