php - Using arrays by reference -
why following code "crashing" in php?
$normal_array = array(); $array_of_arrayrefs = array( &$normal_array ); end( $array_of_arrayrefs )["one"] = 1; // choking on 1
the expected result final code line appends $normal_array
key one
having value 1
there no output ever, not prints preceeding code. in real context of scenario use end() function append last array reference.
this doesn't crash, contains syntax error:
end( $array_of_arrayrefs )["one"] = 1;
unfortunately, cannot treat function return values arrays in php. have assign value explicitly. unfortunately, doesn't work here because end
makes copy of returned value.
Comments
Post a Comment