How to decode multiple json array in codeigniter?

Member

by orpha , in category: PHP Frameworks , 9 months ago

How to decode multiple json array in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by arnoldo.moen , 9 months ago

@orpha 

To decode multiple JSON arrays in CodeIgniter, you can follow these steps:

  1. Load the CodeIgniter JSON library in your controller or model:
1
$this->load->library('json');


  1. Use the json_decode() function provided by the JSON library to decode the JSON string into an array. You can decode multiple JSON arrays by passing true as the second parameter to json_decode():
1
2
3
4
5
$json_string = '[{"name":"John","age":30},{"name":"Jane","age":25}]';

$json_arrays = $this->json->json_decode($json_string, true);

print_r($json_arrays);


  1. You can then access the decoded JSON arrays like any other PHP array:
1
2
3
foreach ($json_arrays as $json_array) {
    echo 'Name: ' . $json_array['name'] . ', Age: ' . $json_array['age'] . '<br>';
}


By following these steps, you can easily decode multiple JSON arrays in CodeIgniter using the JSON library.