How to Convert JSON to Array PHP

By | June 12, 2020

In this article Convert JSON to array PHP tutorial, we started with the What is JSON?
How JSON works with PHP. I divided this issue into 2 sections,

  1. Convert JSON string to Array
  2. Convert JSON string to object.

JSON and PHP array both are also used for data storing. Here we start with the introduction of JSON.

How to Convert JSON to Array PHP

Introduction about JSON

  • JSON stands for JavaScript Object Notation.
  • JSON is used for data exchanging between browser and server.
  • JSON basically is text and written in JS object Notation

When we sending or exchanging the data between server and browser the data must be in text format.

And JSON is text and we can be converting it into JS array, PHP array, and PHP object. In vise versa, we convert PHP array to JSON format and send it into the server.

JSON Syntax

Introduction to PHP Array

I know you all know about PHP array. The array is also a special type of variable that can store one or more values at a time.

In PHP there are 3 types of array ,

  • Indexed arrays – Arrays with a numeric index
  • Associative arrays – Arrays with named keys
  • Multidimensional arrays – Arrays containing one or more arrays

PHP Array Syntax

Convert JSON to Array PHP [ JSON decode ]

Now we check how we Convert JSON string to Array with example. From the above words, you all know about what is an array and JSON and how we declare JSON and array in PHP.

For converting JSON to array in PHP we use JSON decode json_decode() function. So we check with a working example below,

Example JSON to Array PHP

Example JSON to PHP Object

You can copy that code and paste it with PHP tag here for live view,


If you want to convert array to JSON in PHP, you have to use json_encoded() function.

Also check:

Happy Coding..!

Subscribe For Latest Updates

Sign up to best of PHP Code Solutions, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *