Is there any way to check for identity (i.e. being exactly the same object, occupying one and only one place in memory) for two variables representing arrays or objects? (i.e. when one modifies the object named by one variable the changes can be seen in the value of the other variable as they point to the same object/array)
The === operator, for example, checks if two arrays are “identical” in the sense that their elements and their ordering are equal (as opposed to == that doesn’t check ordering for arrays, so for $a = [11, 22]; $b = [1 => 22; 0 => 11];, $a == $b is true but $a === $b is false (because in this latter case the ordering differs, arrays being ordered maps).
My imagined are_identical function would work like this (somewhat like the is in Python):
$a = [11, 22];
$b = [11, 22];
are_identical($a, $b); # => false
$x = [11, 22];
$y = &$x;
are_identical($x, $y); # => true
OK, thanks Artem L and SDC: yes, others have asked about this but in different form so I didn’t know what to look for.
This snippet of code seems to fill the purpose of my
are_identicalfunction (negated):