我這些JSON數據:的Json解碼演示隨着
[{"category":"Pizza","name":"Beef Pronto","desc":"Description of Beef Pronton here","price":"12"},
{"category":"Drink","name":"Cool Delight","desc":"Description of Coold Delight here","price":"5"},
{"category":"Drink","name":"Cola","desc":"Description of Cola","price":"4"}
]
用JavaScript我已經成功地管理的數據呈現如下:
比薩
-Beef普羅託:說明牛肉Pronton here:12
飲料
酷斃了喜悅:5
-cola:可口可樂的說明:4
任何想法如何與PHP做Coold喜悅在這裏的描述?
- >好球員,這是我如何用PHP做:
<?
$listedmenuJSON = '[{"category":"Pizza","name":"Beef Pronto","desc":"Description of Beef Pronton here","price":"12"},
{"category":"Drink","name":"Cool Delight","desc":"Description of Coold Delight here","price":"5"},
{"category":"Drink","name":"Cola","desc":"Description of Cola","price":"4"}
]';
$json_decoded = json_decode($listedmenuJSON);
foreach ($json_decoded as $categoryvalue){
//echo $categoryvalue->category."<br/>";
$tempcategoryvalue[] = $categoryvalue->category;
$arrunique = array_unique($tempcategoryvalue);
}
foreach ($arrunique as $tmpcategory){
echo '<br/><b>'.$tmpcategory.'</b></br>';
foreach ($json_decoded as $tempo){
if($tempo->category == $tmpcategory){
echo $tempo->name.'<br/>';
echo '<i>'.$tempo->desc.'.......</i>';
echo $tempo->price.'<br/>';
}
}
}
?>
它會產生如下:
比薩
牛肉彈指一揮間
這裏的牛肉Pronton的描述....... 12
飲料
酷喜悅
說明Coold喜悅在這裏....... 5
可口可樂
可口可樂的描述....... 4
這是相當有幫助的......至少我知道從哪裏開始,現在 – Gregory 2012-07-12 01:25:24