Reputation: 4517
Please have a look at the following:
foreach($a_Header['Details'] as $i_Detail => &$a_Detail)
{
echo "{$a_Detail['VEH_TREAD_OFF']}\n";
// Make a back-up of the value
$BAK_TREAD_OFF = $a_Detail['VEH_TREAD_OFF'];
// Copy some data from the saved header
foreach(array
(
'POD_QTYORD',
'VEH_TREAD_OFF',
'RPM_SCRM_FIXEDPRICE',
'RPM_TRM_FIXEDPRICE',
'RPM_TRM_COSTPERMM',
'RPM_CTS_CASINGCOST',
'CHARGE_DESC',
'Hide',
) as $s_Column)
{
$a_Header['Details'][$i_Detail][$s_Column] = $a_SavedHeader['Details'][$i_Detail][$s_Column];
}
echo "{$a_Detail['VEH_TREAD_OFF']}\n";
// Now restore our value
$a_Detail['VEH_TREAD_OFF'] = $BAK_TREAD_OFF;
}
You can see that prior to entering the for loop, I have backed up a value which I restore after.
This is because for some reason it is being lost during the loop.
I'm not a PHP guru by any stretch, but this is confusing me no end, as I can't see why modifying one variable would affect another, unless there are wormholes in PHP!
Can someone tell me why this might be happening?
Thanks
Upvotes: 0
Views: 76
Reputation: 626
$i_Detail => &$a_Detail
Now $a_Detail
is a reference to $a_Header['Details'][$i_Detail]
. both variables refer to a single value. Do not use &
if you do not want that.
Upvotes: 1
Reputation: 824
Your code sample does not affect $a_detail at all. Are you sure, this is the only reference to this variable? Do you use something like extract()?
Upvotes: 0