I want to do something like this:
$myArray = array(
'1' => array('2' => array('3' => 'Test'))
);
$changeIt = $myArray['1']['2']['3'];
$changeIt = 'Changed Test';
// $myArray['1']['2']['3'] is now "Changed Test"
Are there ways to do this ?
你可以这样做:
$myArray = array(
'1' => array('2' => array('3' => 'Test'))
);
$myArray['1']['2']['3'] = &$changeIt;//reference
$changeIt = 'Changed Test';
echo $myArray['1']['2']['3']; //Changed Test
$changeIt = 'Another test';
echo $myArray['1']['2']['3']; //Another test
当您编写 $variable = array[key][key]... 时,您将数组的值传递给变量。如果要更改数组本身的值,则需要这样做:
$myArray = array(
'1' => array('2' => array('3' => 'Test'))
);
$myArray['1']['2']['3'] = 'Changed Test';
print_r($myArray);