Nils Ziehn
Nils Ziehn

Reputation: 4331

removing number keys from php array

I want to handle JSON data structures that could look like this:

$json = {"1":"some content here","hello":"world"};

I use the json_decode method from PHP to transform this into an array:

$myArray = (array)json_decode($json);

My problem now is that

unset($myArray["1"]);

Doesn't do anything.

Can you give me any advice? I also tried:

unset($myArray[(String)"1"]);

Thank you!

EDIT: There was an error in my question, thanks for the correction in the comments!

Upvotes: 0

Views: 74

Answers (1)

Nemo64
Nemo64

Reputation: 2683

I think you simply accessed the wrong array

unset($myArray["1"]);
unset($myArray[1]); // works also

Upvotes: 1

Related Questions