How to convert json to array in PHP?
This tutorial will give you simple example convert json to array in php.
1. Code:
<?php function convertJsonToArray($json_data){ $data = json_decode($json_data,true); return $data; } $json_data = '[ { "id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com" }, { "id": 2, "name": "Jaydeep Pathar", "email": "jaydeep@gmail.com" }, { "id": 3, "name": "Vivek Pathar", "email": "vivek@gmail.com" } ]'; print_r(convertJsonToArray($json_data)); ?>
2. Example:
Input:
[ { "id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com" }, { "id": 2, "name": "Jaydeep Pathar", "email": "jaydeep@gmail.com" }, { "id": 3, "name": "Vivek Pathar", "email": "vivek@gmail.com" } ]
Output:
[ [ "id" => 1, "name" => "Hardik Savani", "email" => "hardik@gmail.com"], [ "id" => 2, "name" => "Jaydeep Pather", "email" => "jaydeep@gmail.com"], [ "id" => 3, "name" => "Vivek Pather", "email" => "vivek@gmail.com"] ]