Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:36:05+00:00 2026-06-12T01:36:05+00:00

I got an array and check if end() exists or is empty. If it

  • 0

I got an array and check if end() exists or is empty. If it is empty I would like to get the previous object of the array. I tried using prev() but that didn’t seem to work when applied to end().

any suggestions? the array can vary in lenght and size.

Thanks for your help guys!

Some code:

$pagination = esc_url( get_next_posts_page_link()); // returns url with slashes
$parts = explode('/', $pagination);
//get the last item
$tag = end($parts);
if ($tag == ""){echo prev($tag); } else{echo $tag;}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:36:06+00:00Added an answer on June 12, 2026 at 1:36 am

    You should not apply prev() on the result of end() but on the original array as both functions are manipulating the internal array pointer of that array.

    So:

    if ($tag == ""){echo prev($parts); } else{echo $tag;}
    

    Edit: By the way, you can also do a trim($pagination, '/') before you explode so that the last item will never be empty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to know how to check an array that got several variables in
I've got an array A. I'd like to check if it contains duplicate values.
I use in_array() to check whether a value exists in an array like below,
I'm using extension methods based on an array and I would like to know
If I've got an array of strings, can I check to see if a
I got an array like that Array ( [0] => Array ( [UnitESN] =>
I've got an array of strings that looks like this: [noindex,nofollow] or [index, follow,
I've got an object like this: var obj = { age:[23], part:[0], race:[], state:[AL],
ive got an array like this: $display_related_tags[0][20] = 'text1'; $display_related_tags[1][21] = 'text2'; $display_related_tags[2][22] =
I know vBulletin uses bitperms, I was using them too but when I got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.