Skip to content
Advertisement

Array search to get key value doesn’t work after json_decode

I have this JSON code:

JavaScript

I am having this array below out of using json_decode:

JavaScript

I want to use the array_search https://www.php.net/manual/en/function.array-search.php

So I wrote this:

JavaScript

I expected $key to be 1 but it is empty if I do echo $key;

Below my complete code:

JavaScript

Advertisement

Answer

If you … want to use the array_search() function, you need to use json_decode() with true as second parameter to decode the JSON string and convert the JSON content into associative arrays:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement