MoFish1 Posted October 25, 2019 Share Posted October 25, 2019 Hello, I'm trying to loop out the following value from the below array and cannot figure it out - orders.orderid Could anyone help me? stdClass Object ( [recsindb] => 4320 [recsonpage] => 10 [9] => stdClass Object ( [orders.orderid] => 83269442 ) [8] => stdClass Object ( [orders.orderid] => 83267681 ) ) echo "<pre>"; print_r($data); echo "<pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/309413-array-loop-help/ Share on other sites More sharing options...
Barand Posted October 25, 2019 Share Posted October 25, 2019 That "array" is an object. (if it came from json data, decode it as an array instead of an object) $a = json_decode(json_encode($data), true); // convert the object to an array foreach ($a as $k => $v) { if (is_array($v)) { echo $v['orders.orderid'] . '<br>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/309413-array-loop-help/#findComment-1571004 Share on other sites More sharing options...
MoFish1 Posted October 25, 2019 Author Share Posted October 25, 2019 (edited) Hi Barand, Thanks for your help. Apologies, I'm happy for it to be an object. How can i access loop around the object? Thanks, MoFish Edited October 25, 2019 by MoFish1 Quote Link to comment https://forums.phpfreaks.com/topic/309413-array-loop-help/#findComment-1571005 Share on other sites More sharing options...
Barand Posted October 25, 2019 Share Posted October 25, 2019 foreach ($data as $k => $v) { if (is_object($v)) { foreach ($v as $k1 => $v1) { echo "$k1 : $v1 <br>"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/309413-array-loop-help/#findComment-1571006 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.