String Into Array

I have a string

{"Service":4,"Happy":2,"Next Guess":3,"Ninja":4,"Puppy":54}

What would be the best way to get it into an array and use that to display a table

[table]
[tr][td]Service[/td][td]4[/td][/tr]
[tr][td]Happy[/td][td]2[/td][/tr]
[tr][td]Next Guess[/td][td]3[/td][/tr]
[tr][td]Ninja[/td][td]4[/td][/tr]
[tr][td]Puppy[/td][td]54[/td][/tr]
[/table]

This should work, as your string seem to be a valid json encoded array:
[php]<?php
$s = ‘{“Service”:4,“Happy”:2,“Next Guess”:3,“Ninja”:4,“Puppy”:54}’;

// decoding json string into array
$arr = json_decode($s);

// displaying array data in html table
echo ‘

’;
foreach($arr as $key=>$val){
echo ‘’;
}
echo ‘
’.$key.’ ’.$val.’
’;
?>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service