1

How can I tell if an element in an array is a reference?

Consider the following code:

$a = ['a1', 'a2'];
$b = ['b1', &$a];

var_dump($b);

The output of var_dump($b) is:

array(2) {
  [0]=>
  string(2) "b1"
  [1]=>
  &array(2) {
    [0]=>
    string(2) "a1"
    [1]=>
    string(2) "a2"
  }
}

As you can see, var_dump() knows that array $a is by reference inside array $b.

Is there a way to tell that an element of an array is actually a reference?

Richi RM
  • 829
  • 3
  • 11
  • 1
    I don't know of any bulletproof way of checking that, but may I ask why you need it and what problem it would solve? Imho, if you need to know that at runtime, it's probably a sign of some bigger design flaw. – M. Eriksson Nov 29 '21 at 09:12
  • check this links : https://stackoverflow.com/questions/4817562/detecting-whether-a-php-variable-is-a-reference-referenced and check this : http://xdebug.org/ . found that may be usefull – Rouissi Iheb Nov 29 '21 at 09:16

0 Answers0