How to convert JSON into an array in PHP?

You can use the json_decode() function to convert a JSON string into an array. For example:

$jsonString = '{"name": "John", "age": 30, "city": "New York"}';
$array = json_decode($jsonString, true);

print_r($array);

The code above converts the JSON string $jsonString into an array $array, and then prints out the content of the array using the print_r() function. Setting the second parameter of the json_decode() function to true allows the JSON object to be converted into an associative array instead of the default object.

bannerAds