Solution for I’m getting issue while for each the nested array
is Given Below:
Given Array
Array
(
[status] => 1
[error] => 0
[list] => Array
(
[0] => Array
(
[id] => 1
[name] => Bandtoer
[data] => Array
(
[0] => OVERLAND
[1] => DETAIN
[2] => OVERNIGHT
)
[origin] => 1
[destination] => 1
)
)
)
Want to display all the array
Code
foreach ($response as $list => $val) {
foreach ($list as $atr => $val2) {
echo $list;
foreach ($atr as $atr1 => $val3) {
echo $atr1 . ":" . $val3 . ":";
}
}
}
I mean to display these nested array but could not so far, I am also getting the error Illegal string offset please help me where I am going wrong
Please check the foreach syntax. Foreach iterates the array item using $key and $val format. $key could be integer or string index.
https://www.php.net/manual/en/control-structures.foreach.php
In the nested foreach, you are trying to loop through a key which cannot be an array at any instance