I want to implement a function
$input = ['key1', 'value1', 'key2', 'value2'];
// $output = ['key1' => 'value1', 'key2' => 'value2'];
$output=[];
do {
$output[current($input)] = next($input);
} while (next($input));
I wrote this code intuitively, but when I reviewed this code today, I pondered if this might be a bug.
I assumed the output should be something like this:
['value1'=>'value1','value2'=>'value2']
because next()
takes precedence over current()
, but this function works fine in PHP8.
Why is this? Isn't assignment from right to left?