Hi i have an array coming from json data of placed order items in my api in this form. let's suppose this example :

[items] => Array
            [0] => stdClass Object
                 [item_id] => 392
                 [name] => ketchup 20g
                 [qty] => 2

            [1] => stdClass Object

                    [item_id] => 393
                    [name] => Powder 
                    [qty] => 1


-------------php code for dumping array data on screen -------

 $result=  json_decode($result);
 echo "<pre>";
 echo "</pre>";

........... Basically i wants to fetch all order items placed by customer in one order.

echo $result->items[0]->name;

this code is returning one item name at a time manually ,but let's suppose if one order has multiple items , how can i fetch it through loop? please guide

2 Answers 2


in my case due to array data are coming in multiple indexes so this worked for me: i hope it may help anybody

foreach ($result2 as  $value) {

      foreach($value as  $value2)

        foreach($value2 as $value3)
            foreach($value3->items as $value4)
                    echo '<br>';

This is a standard way to do it.

$jsondata = '';
$arr = (array)json_decode($jsondata, true);
 foreach ($arr as $k=>$v){
    echo $v; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.