i am so stuck , please someone help if you have 2 min.
i have a foreach where I get values from session something like
foreach ($result as $i => $item ) {
$values_array = explode("\n",$get_widths); // outputs Array ( [0] => 120 [1] => 180)
// here I need to echo the value from the array but only ONCE
}
the issue is that this is used by 2 or more items and array outputs gets repeated every time , so if 2 items i get
Array ( [0] => 120 [1] => 180) Array ( [0] => 120 [1] => 180) or
120 120
instead
120 180
for actual code see here
<?php
foreach ($list as $i => &$item){
$i=0;
$is_group = $item_params->get('is_group');
$group_widths = $item_params->get('group_widths');
$group_widths_array = explode("\n",$group_widths);
if($is_group == 1){
echo $group_widths_array[$i];
}
}
?>
please note I cant move outside the foreach. thank you
I am completely missing the point of this loop…
You are iterating over an array, assigning the key to
$iand the value to$itembut then you set$ito 0, echoing$group_widths_array[0]every time your condition is met and$itemyou don´t use at all…That can´t be right, can it?
Anyway, it seems to me that the reason that your output is repeated is that you output
$group_widths_array[0]every time and$is_groupis the same on every iteration.