How to json_decode to array with PHP?

Spread the love

Sometimes, we want to json_decode to array with PHP.

In this article, we’ll look at how to json_decode to array with PHP.

How to json_decode to array with PHP?

To json_decode to array with PHP, we call json_decode with true.

For instance, we write

$result = json_decode($jsondata, true);

to call json_decode with the $jsondata string and true to parse the $jsondata string to parse the string into an associative array.

We write

$result = array_values(json_decode($jsondata, true));

to call array_values to return an array from the associative array returned by json_decode.

Conclusion

To json_decode to array with PHP, we call json_decode with true.

Leave a Reply

Your email address will not be published.