$array = array();
$array[ 'recursive' ] =& $array;
$array[ 'foo' ] = $array;
'foo'
was assigned by value to $array
, which should copy $array
, which did not have a 'foo'
key at the time, so I expect the situation to now be something like:
$array = array(
'recursive' => &$array,
'foo' => array(
'recursive' => &$array
),
)
But if I now do:
var_dump( isset( $array[ 'foo' ][ 'foo' ][ 'foo' ] ) );
I get:
bool(true)
I don't understand why this is.
If I create an intermediate variable for the assignment of 'foo'
, like this:
$array = array();
$array[ 'recursive' ] =& $array;
$blah = $array;
$array[ 'foo' ] = $blah;
var_dump( isset( $array[ 'foo' ][ 'foo' ][ 'foo' ] ) );
I get:
bool(false)
I understand why the 'recursive'
key would be infinitely deep, because that was assigned by reference, but why the 'foo'
key, which was assigned by value? How can creating an intermediate variable change behaviour for things handled by value?