The answer is yes. But it has nothing to do with the value itself, the fact is that the position of the key is that it contains the value. The pointer only tells you what the current key is, and if this key contains the current value, then, yes, it is composing its value. Whenever using an array, part of the premise that the position or key is who has value, and nothing else, the array is basically a collection of keys that have values.
Variable association is an exact copy of its origin... so it is evident that yes.
Even if there is one last interaction, which changes its origin behavior, internally it is a new structure, in this sense you will be copying this new structure, with its new conditions and rules, it has been mutated, and now this is also part of the array scope.
Every array has an internal pointer to the "current" element, which is initialized to point to the first element inserted in an array.
The function Current() simply returns the element of the array to which this internal pointer is pointing. It does not move the pointer at all. If the internal pointer is pointing beyond the end of the list of elements or the array is empty, Current() returns FALSE.
end() - Makes the internal pointer of an array point to its last element
key() - Returns a key from an array
each() - Returns the key pair/current value of an array and advances its cursor
Prev() - Back the internal pointer of an array
reset() - Makes the internal pointer of an array point to its first element
next() - Advance the internal pointer of an array
When defining a common array with values, no keys: $array = ('valor 1', 'valor 2', 'valor 3')
, by default, when we do not define the keys, it is interpreted by number 0, 1, 2... in this way, internally it is the same thing, it has a pre-established order of inclusion of the keys/values:
$array = array(
0 => 'valor 1', /* internamente : -> current é 'valor 1',
que é chave 0 (pois é o primeiro valor a
ser inserido no array */
1 => 'valor 2',
2 => 'valor 3'
);
When using the method: next($array)
, for example, you are internally modifying the position of the current (Current) value inserted in the array, to the next, but the key and the value remain in the same place, if you sort it, you will notice that the order of the keys nay changed nothing visually:
sort($array);
print_r($array);
Exit:
Array
(
[0] => valor 1
[1] => valor 2
[2] => valor 3
)
$array[1]
that holds key 1, and value 'valor 2'
. That is, using the method current($array)
, you will be getting the key and value of the new "internal position".
Yes, there is an interene value in the array that says which element it is pointing to, i.e., when copying the array it must copy yes the value of the current pointer. See more information here and here.
– fajuchem
@fajuchem has already answered the question!
– Ivan Ferrer
@Ivanferrer He commented on a possible response, but has not yet responded.
– Woss
@fajuchem would be interesting to formalize as a response, taking the relevant part of the links
– Bacco