I found this? Is this the best way to do it?
I'm looking to use some sort of repeat loop with variables that throw in JSON data.
I am using Codeignitor and jquery.
Thanks
I found this? Is this the best way to do it?
I'm looking to use some sort of repeat loop with variables that throw in JSON data.
I am using Codeignitor and jquery.
Thanks
If you mean that you want something that turns JSON into a PHP variable or object, I think this code will explain it:
Code:
<?
// here is an array
$myarray = array(
'animal' => 'dog',
'plant' => 'tree',
'anotherArray' => array ('some' => 'data'),
);
// print out the array to show what it looks like
print_r($myarray);
// convert the array to json
$jsonArray = json_encode($myarray);
// print out the json data
print $jsonArray.'\n';
// convert the json data back into a PHP array
$phpArray = json_decode($jsonArray);
// print out the array that went from PHP to JSON, and back to PHP again
print_r($phpArray);
Output:
Array
(
[animal] => dog
[plant] => tree
[anotherArray] => Array
(
[some] => data
)
)
{"animal":"dog","plant":"tree","anotherArray":{"some":"data"}}
stdClass Object
(
[animal] => dog
[plant] => tree
[anotherArray] => stdClass Object
(
[some] => data
)
)