Nickolas
Member
I have found out that when we run this code the result is below (Result B). But expected result should be
Result A:
I believe that this is pointer/reference related error.
Should we consider this as an error or PHP syntax related limitation? Because when I change the second loop's reference array name ($value) this problem disappears.
NOTE: PHP version 5.3.2, Zend Server, Linux 2.6.32-28-generic-pae
Result B:
Result A:
Code:
Array
(
[0] => Test
[1] => Tested
[2] => Test
)
Array
(
[0] => Test 1
[1] => Tested
[2] => Test 1
)
I believe that this is pointer/reference related error.
Should we consider this as an error or PHP syntax related limitation? Because when I change the second loop's reference array name ($value) this problem disappears.
NOTE: PHP version 5.3.2, Zend Server, Linux 2.6.32-28-generic-pae
PHP:
<?php
$array = array(1 => array('Test', 'Test', 'Test'), 2 => array('Test 1', 'Test 1', 'Test 1'));
foreach ($array AS $index => &$value)
{
$value[1] = 'Tested';
}
foreach ($array AS $index => $value)
{
print_r($value);
}
?>
Result B:
Code:
Array
(
[0] => Test
[1] => Tested
[2] => Test
)
Array
(
[0] => Test
[1] => Tested
[2] => Test
)