DamienRoche Posted February 24, 2009 Share Posted February 24, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146748-delete-last-entry-in-array/ Share on other sites More sharing options...
premiso Posted February 24, 2009 Share Posted February 24, 2009 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]); Quote Link to comment https://forums.phpfreaks.com/topic/146748-delete-last-entry-in-array/#findComment-770444 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.