I created a simple test case that replicates an issue I'm having.
I'm walking through a two dimensional array using the next() and current() functions, and am wanting to setup the array pointer to a specific location. So, given a 2D array with a variable name of $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 code snippet:
// move the inner array's pointer once
$should_be_orange = next(current($food));
// now check that inner array's 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 inner array, who's pointer gets iterated, and then destroyed (leaving the original array untouched)? Or am I simply doing something wrong that I'm not catching?
At the root of the question, how do you move the inner array's pointer given that you don't know the outer array's key (and must use the current() function to obtain the outer array's pointer location)?