Jump to content

Recommended Posts

Ok, array_pop doesn't suit what I need.

 

I simply need to chop the last entry off an array..is there an simple way of doing this because I haven't found anything from searching for the last 20 minutes.

 

I cannot delete based on key or value, I need to delete the last entry - on that only condition.

 

Any help greatly appreciated. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/146748-delete-last-entry-in-array/
Share on other sites

Why does array_pop not work for you?

 

Can you post some of the code you are working with, cause what you are saying is basically that this element may not be the last element, hence why array_pop does not work and it could be an associative array, hence the count($array) would not work to determine the last element.

 

How exactly is this array setup? You can use a foreach and loop through storing the $key foreach element then at the end just unset that key.

 

foreach ($array as $key => $val) {
     $unset = $key;
}
unset($array[$unset]);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.