I created a simple test case that replicates the problem I have.
I am going through a two-dimensional array using the next() and current() functions, and I want to set the array pointer to a specific location. So, given a 2D array with the variable name $food with the following array structure:
array 0 => <-- POINTER LOCATION array 0 => string 'apple' <-- POINTER LOCATION 1 => string 'orange' 1 => array 0 => string 'onion' 1 => string 'carrot'
... and the following piece of code:
// move the inner array pointer once $should_be_orange = next(current($food)); // now check that inner array value $should_still_be_orange = current(current($food));
... Why is the value of $should_be_orange "orange", but the value of $should_still_be_orange "apple"? Is this because the current() function returns a copy of the internal array, which the pointer gets iterated and then destroyed (leaving the original array intact)? Or am I just doing something wrong that I will not catch?
At the root of the question, how do you move the pointer of an internal array, given that you do not know the key of the external array (and should use the current() function to get the location of the pointer of the external array)?
source share