PHP code for JSON Array Example
This PHP code snippet was generated automatically for the JSON Array example.<< Back to the JSON Array example
What is JSON?
JavaScript Object Notation (JSON) is a lightweight, language-independent, text-based data exchange format. JSON specifies a set of rules for representing structured data in a portable manner. JSON supports four primitive types (strings, numbers, boolean values, and null) and two structured types (objects and arrays). Many programming languages use JSON to exchange data, including JavaScript, Java, C++, C#, Go, PHP, Python, and many others.
JSON Array Examples
JSON arrays come in different types: strings, numbers, booleans, objects, and multidimensional arrays. Below are examples of JSON array types with a detailed description:
JSON Array of Strings
The JSON array of strings contains only string elements, where each element is separated by a comma (,). The following is an example of a JSON array storing string values:
JSON Array of Numbers
The JSON array of numbers contains only numeric elements. Below is an example of a JSON array storing numeric values:
JSON Array of Booleans
The JSON array of booleans contains only booleans (either true or false). The following is an example of an array of JSON booleans:
JSON Array of Objects
A JSON object is similar to a JavaScript object. We can also create a JSON array containing many objects, and then we can iterate over this array or use "[]" square brackets to get the desired object. Below is an example of an array of JSON objects:
JSON Nested Array
JSON arrays can contain various arrays as elements. You can use the "[]" operator to get an array at any index and use the "[]" operator again to get an element of the selected array. The following is an example of creating a multidimensional JSON array:
JSON Mixed Array
The mixed JSON array contains various types of elements. Below is an example of a JSON array that stores mixed values: