Possible Duplicate:
JSON Parsing with PHP
I’m hoping for a little assistance on this. I trying to take what’s in my $data variable:
[{"Product":"Internal",
"Rank":"1",
"Number":"1234"},
{"Product":"External",
"Rank":"1",
"Number":"5678"}]
and turn it into an associative array that is something like this:
Product[0] => Internal,
Rank[0] => 1,
Number[0] => 1234,
Product[1] => External,
Rank[1] => 1,
Number[1] => 5678
The closest I’ve been able to get is using the following code:
$del='/[{: ,}]/';
$data = preg_split($del,$data);
print_r($data);
Which gives me something like this:
Array ( [0] => [ [1] => “Product” [2] => “1 [3] => 1” [4] => “Rank”
[5] => “1”
Any suggestions would be greatly appreciated. Thanks for your time!
If you know that
$datais in JSON format, you could just do this:Then you want to iterate through the array of objects and transmogrify them: