I have an array from which I want to remove the first element, but when I do this and send the information as JSON, the result is read as an object.
The PHP array is as follows:
$myArray = ["one", "two", "three", "four"]
and when I send this as JSON with json_encode($myArray)
, this happens as I expected:
["one","two","three","four"]
But then, when I first disconnected:
unset($myArray[0]);
... the JSON I got from json_encode($myArray)
reads:
{"1":"one","2":"two"}
What makes it so, and how can I prevent it from appearing in object notation?
From what I see, in PHP the remaining array behaves like an array, and I can use array functions like array_search
, array_intersect
, etc.
source share