Different between &$DataRow and $DataRow
Posted
by KoolKabin
on Stack Overflow
See other posts from Stack Overflow
or by KoolKabin
Published on 2010-05-11T10:52:05Z
Indexed on
2010/05/11
11:14 UTC
Read the original article
Hit count: 314
php
hi guys,
I am confused from the result of the following code: I can't get my expected result:
$arrX = array('a'=>array('val'=>10),'b'=>array('val'=>20), 'c'=>array('val'=>30));
foreach( $arrX as &$DataRow )
{
$DataRow['val'] = $DataRow['val'] + 20;
}
foreach( $arrX as $DataRow )
{
echo '<br />val: '.$DataRow['val'].'<br/>';
}
Output: 30, 40, 40
Expected: 30, 40, 50
But again if i make small chage it works fine,
$arrX = array('a'=>array('val'=>10),'b'=>array('val'=>20), 'c'=>array('val'=>30));
foreach( $arrX as &$DataRow )
{
$DataRow['val'] = $DataRow['val'] + 20;
}
foreach( $arrX as &$DataRow )
{
echo '<br />val: '.$DataRow['val'].'<br/>';
}
© Stack Overflow or respective owner