You need to disable $DataRow after the loop in which you use it as a reference:
$arrX=array('a'=>array('val'=>10),'b'=>array('val'=>20), 'c'=>array('val'=>30)); foreach( $arrX as &$DataRow ) { $DataRow['val'] = $DataRow['val'] + 20; }
You can use another variable and avoid canceling ... although I would not recommend it, since $ DataRow still refers to the last element of the array, and any subsequent rewriting can cause problems.
$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 $foo) {
source share