I have the following array
Array(
Array
(
[Segment] => Array
(
[id] => 738
)
),
Array
(
[Segment] => Array
(
[0] => array([id] => 740),
[1] => array([id] => 750)
)
)
)
how can i loop the array. The second value need inner loop.
i need the output as
first loop as id->738
second loop as id->740, id->750
Regards, Nisanth
You can do it like this:
foreach($array as $a) {
foreach($a as $segment => $array) {
if(isset($array['id'])) {
echo $array['id']; //if there is an `id` index echo it
} else {
foreach($array as $k => $v) { //or else.. start looping again
echo $v['id'];
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With