ここで何が起こっているのか説明してくれませんか。
$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);
出力:
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" } }
これは通常、配列として保持されますが、配列の一部を設定解除するとすぐに、それが 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);
出力:
object(stdClass)#1 (1) { ["1"]=> object(stdClass)#2 (3) { ["one"]=> string(3) "uno" ["two"]=> string(3) "dos" ["three"]=> string(4) "tres" } }
一貫性を保つにはどうすればよいですか?