I've looked around but haven't found an answer so I figured i would give it an ask myself.
I've noticed that a round trip to JSON converts a 2-D array into a 1D array of Objects.
Is there any way around this or should I just try to work with objects from the beginning (e.g. $test->1->4 ? see example below
$test = array();
$test[0][0] = "0-0";
$test[0][2] = "0-2";
$test[1][1] = "1-1";
$test[1][2] = "1-2";
var_dump($test);
$encoded = json_encode($test);
var_dump($encoded);
$recreated = json_decode($encoded);
var_dump($recreated);
outputs
array(2) {
[0]=>
array(2) {
[0]=>
string(3) "0-0"
[2]=>
string(3) "0-2"
}
[1]=>
array(2) {
[1]=>
string(3) "1-1"
[2]=>
string(3) "1-2"
}
}
string(45) "[{"0":"0-0","2":"0-2"},{"1":"1-1","2":"1-2"}]"
array(2) {
[0]=>
object(stdClass)#19 (2) {
["0"]=>
string(3) "0-0"
["2"]=>
string(3) "0-2"
}
[1]=>
object(stdClass)#20 (2) {
["1"]=>
string(3) "1-1"
["2"]=>
string(3) "1-2"
}
}