Loading, please wait...

A to Z Full Forms and Acronyms

How to decode the JSON string into an associative array in PHP | PHP program

Feb 22, 2022 PHP, 2303 Views
How to decode the JSON string into an associative array in PHP | PHP program

How to decode the JSON string into an associative array in PHP | PHP program

We will convert a JSON string into an associative array using the json_decode() function and print the elements of the associative array on the webpage.

<?php

$json = '{"Id1":101,"Id2":102,"Id3":103,"Id4":104}';
$ids = json_decode($json);

foreach ($ids as $key => $value)
{
    print ("Key: " . $key . " Value: " . $value . "<br/>");
}
?>
A to Z Full Forms and Acronyms