Return a PHP array by reference
Looks like I'm using way to much Java in these days... I'm starting to forget PHP knowledge. Today I was searching for a function to clone an array but haven't found one. I was curious why PHP doesn't have an array_clone or array_copy function. But then I was nudged into the right direction: Arrays are always assigned by value, not by reference, so it simply doesn't need a clone function because a simple assignment already performs a clone (It's even some sort of deep clone (At least all values inside the array (Arrays are also values, not objects) are copied)). To assign it by reference you have to add an ampersand character:
$arr = array(); $arrClone = $arr; // A clone is created $arrRef = &$arr; // A reference is created
I really forgot this basic PHP knowledge...