How can i insert the JSON array in PHP Dynamically -
this question has answer here:
- how extract data json php? 2 answers
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>'; ?>
Comments
Post a Comment