javascript - Creating "objects" and "arrays" in PHP in a way that would allows JS to distinguish between them -


php's syntax create array (either indexed or assosiative) same, aka

$arr = []; 

however, json_encode convert empty php "array" (note quotes) empty js array ([]), not desirable in situations.

is there way can create empty assosiative array in php, json_encode convert empty js object, aka {}, instead of [].

you can use stdclass:

$obj = new stdclass(); echo json_encode($obj); 

this gets me intended {} output.


Comments