How can i insert the JSON array in PHP Dynamically -


this question has answer here:

i have json file contain 3 array have same key brand, reference in 3 array how can dynamically insert these data php. if increase json array data print dynamically.

json

[{     "brand": "29\/25 prospring",     "reference": "bc0290c", },  {     "brand": "alpha",     "reference": "bc23weq", }  {     "brand": "30/40 resin",     "reference": "bc23mju", }] 

php

<?php  error_reporting(0);  $json_file = file_get_contents('jsonfile.json');  $somearray = json_decode($json_file, true);   ?>  

html

<div class="page4">  <a href="product.php">29\/25 prospring</a>   </div>  

<?php     $json = file_get_contents("jsonfile.json");      $jsoniterator = new recursiveiteratoriterator(                     new recursivearrayiterator(json_decode($json, true)),                     recursiveiteratoriterator::self_first);     $arr = [];      foreach($jsoniterator $key => $val) {         if(is_array($val)) {             $arr[$key]=$val;         }     }      echo '<pre>';     print_r($arr);     echo '</pre>'; ?> 

output: enter image description here


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -