具有指定标签的PHP Json值

I am using json_decode and echoing the values using a nested foreach loop.

Here's a truncated json that I am working on:

[{"product_name":"Product 1","product_quantity":"1","product_price":"2.99"},....

and the loop

foreach($list_array as $p){
    foreach($p as $key=>$value) {
        $result_html .= $key.": ".$value."<br />";
    }
}

This was I am able to echo all key/value pairs.

I have tried using this to echo individual items something like:

foreach($list_array as $p){
    foreach($p as $key=>$value) {
        echo "Product: ".$p[$key]['product_name'];
        echo "Quantity: ".$p[$key]['product_quantity'];
    }
}

However I am unable to because it doesn't echo anything.

I would like to be able to show something like:

Product Name: Apple

Quantity: 7

Currently it is showing:

product_name: Apple

product_quantity: 7

How can I remove the key and replace it with a predefined label.

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;

It can be done with:

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