i have problem with foreach loop, i have one variable with multiple arrays like those two on the bottom and i need to get arrays from [sub] level up... i use
foreach ($global['sub'] as $sub) {
$global['sub'] = $sub;
$global['child_id'] = $sub['id'];
$global['child_name'] = $sub['name'];
$global['child_url'] = $pr. $sub['url'];
}
but it works only for arrays that have arrays in [sub] but doesn't return second array where [sub] is empty I try to get all arrays i $global variable those that have sub arrays in [sub] and those that doesn't have as well...
Array
(
[Segment_id] => ......
[Segment] => ......
[Segment_url] => ......
[Categories_id] => ......
[Categories] => ......
[Categories_url] => ......
[sub_Categories_id] => ......
[sub_Categories] => ......
[sub_Categories_url] => ......
[categoryId] => ......
[categoryName] => ......
[product_count] => ......
[sub] => Array
(
[0] => Array
(
[id] => ......
[name] => ......
[anchor] =>
[url] => ......
[description] =>
[productCount] => ......
[products] => ......
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
)
)
and
Array
(
[Segment_id] => ......
[Segment] => ......
[Segment_url] => ......
[Categories_id] => ......
[Categories] => ......
[Categories_url] => ......
[sub_Categories_id] => ......
[sub_Categories] => ......
[sub_Categories_url] => ......
[categoryId] => 1394
[categoryName] => ......
[product_count] => ......
[sub] => Array
(
)
i need to get
Array
(
[Segment_id] => .....
[Segment] => .......
[Segment_url] => .......
[Categories_id] => .....
[Categories] => .....
[Categories_url] => ......
[sub_Categories_id] => ....
[sub_Categories] => .....
[sub_Categories_url] => ......
[categoryId] => 397
[categoryName] => ......
[product_count] => ......
[subid] => .....
[sub_name] => ......
[sub_url] => ......
[description] =>
[sub_productCount] => ......
second one that doesn't have anything in [sub] might be as is now...
source https://stackoverflow.com/questions/70249883/how-to-return-arrays-that-foreach-doesnt-catch
No comments:
Post a Comment