I'd like to get last element of an array in PHP.
I often do this:
$last = $this->array_of_stuff[count($this->array_of_stuff) - 1];
I'm not very happy with that though.
Any way to make the syntax shorter and avoid repeating code?
I'd like to get last element of an array in PHP.
I often do this:
$last = $this->array_of_stuff[count($this->array_of_stuff) - 1];
I'm not very happy with that though.
Any way to make the syntax shorter and avoid repeating code?
You can use end
function for this case. See the manual
end($array)