I need to select the last element in a particular array. For example I need the last element in this array which is currently set to the forth or [3]

1 Answer
end() will return the last element of an array.
$last = end($categories);
echo $last['category_id'];
Note: Be mindful this also sets the internal array pointer.
2 Comments
Scott C.
Thanks Jason. I figured it was the end() command but didn't know how to use it in this particular case. Your example works perfectly.
Jason McCreary
No problem. Don't forget to mark answers when you find one that works for you.