Note that there are some explanatory texts on larger screens.

plurals
  1. POJson Decode Presentation With Category
    text
    copied!<p>I got these Json data:</p> <pre><code>[{"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"} ] </code></pre> <p>With Javascript I have successfully managed data to present as follow:</p> <p><strong>Pizza</strong></p> <p>-Beef Pronto: Description of Beef Pronton here: 12</p> <p><strong>Drink</strong></p> <p>-Cool Delight: Description of Coold Delight here: 5</p> <p>-Cola: Description of Cola: 4</p> <blockquote> <p>any Idea how to do it with <strong>PHP</strong> ?</p> </blockquote> <p><strong>-->Ok guys, this is How I do it with PHP:</strong></p> <pre><code>&lt;? $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-&gt;category."&lt;br/&gt;"; $tempcategoryvalue[] = $categoryvalue-&gt;category; $arrunique = array_unique($tempcategoryvalue); } foreach ($arrunique as $tmpcategory){ echo '&lt;br/&gt;&lt;b&gt;'.$tmpcategory.'&lt;/b&gt;&lt;/br&gt;'; foreach ($json_decoded as $tempo){ if($tempo-&gt;category == $tmpcategory){ echo $tempo-&gt;name.'&lt;br/&gt;'; echo '&lt;i&gt;'.$tempo-&gt;desc.'.......&lt;/i&gt;'; echo $tempo-&gt;price.'&lt;br/&gt;'; } } } ?&gt; </code></pre> <p>It will generate as following:</p> <p><b>Pizza</b><br/> Beef Pronto<br/> <i>Description of Beef Pronton here.......12</i></p> <p><b>Drink</b><br/> Cool Delight<br/> <i>Description of Coold Delight here.......5</i><br/> Cola<br/> <i>Description of Cola.......4</i></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload