PHP Json values with a specified label PHP Json values with a specified label json json

PHP Json values with a specified label


It can be done with:

foreach ($list_array as $p){    $result_html .= 'Product: ' . $p->product_name         . 'Quantity: ' . $p->product_quantity . '<br />';}


If you are decoding your json into an object you can do it like that.

$list_array = json_decode('[{"product_name":"Product 1","product_quantity":"1","product_price":"2.99"}]');$result_html = '';foreach($list_array as $p){    $result_html .= '<div>Product: '.$p->product_name.'</div>';    $result_html .= '<div>Quantity: '.$p->product_quantity.'</div>';}echo $result_html;