In PHP, does the inner pointer of an array make up its value?

3

Consider the following array :

$a = [1, 2, 3, 4, 5];

However, I noticed that the pointer position of the array is also copied. If before we set $b = $a to be a copy of $b we change the position of the pointer:

$a = [1, 2, 3, 4, 5];

next($a);  // Move o ponteiro interno uma posição a frente

$b = $a;

When checking the current value of $a , we will have the value 2, because the pointer is in the second position:

echo current($b);  // 2

When we move the pointer of $b before the copy, the array $a will already be generated with the new position of the pointer; but if pointer position changes after copying, the change does not affect $b .

So, the position of the inner pointer of an array make up its value, copied together when the object is copied? Would that be expected? My impression was that by copying an array I would copy only the values by restarting the position of the pointer.

    
asked by anonymous 06.12.2018 / 15:14

0 answers