Is there a way to create a PHP array which always treated by reference without having to use the & operator?
For instance:
$a = array_by_ref('a', 'b', 'c');
$b = $a;
$b[] = 'd';
should result in both $a and $b being equal to:
('a', 'b', 'c', 'd')
If SPL is available, there is the
ArrayObjectclass:These are still wrapper objects though; to get their primitive array equivalents you have to use the object’s
getArrayCopy()method. Also bear in mind that it can be quite slow, particularly when you iterate through its elements.