1

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] enter image description here

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
No problem. Don't forget to mark answers when you find one that works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.