I attempted to pass an explode statement into end() and got the following notice from my IDE, "Only variables can be passed by reference", which is not surprising.
However, what confuses me is that if I do something like
$array = ['cat', 'dog', 'bird'];
end($array);
echo print_r($array, true);
['cat', 'dog', 'bird'] prints out.
It is/was my understanding that passing something by references changes the value of the variable so I had expected $array to only print out 'Bird' after being passed into end().
I suspect I have a fundamental misunderstanding of passing something by reference...
The end() function moves the internal pointer to, and outputs, the last element in the array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.
end()
function returns a value and does not change the reference array!
so you may save the value to another variable first. in fact it returns the value of the last element or false for empty array.
so you may try:
$array = ['cat', 'dog', 'bird'];
$last = end($array);
echo print_r($last, true);