Aarav123 Posted November 4, 2016 Share Posted November 4, 2016 Hi, While learning PHP programming & applications, I encountered an issue where I need to point last element of an array in PHP. I have searched in many php developer forum for this solutions but still issue remains the same. Hoping to get a solution from the fellow tech experts. Quote Link to comment https://forums.phpfreaks.com/topic/302462-how-to-point-last-element-of-an-array-in-php/ Share on other sites More sharing options...
PravinS Posted November 4, 2016 Share Posted November 4, 2016 Check this: http://php.net/manual/en/function.end.php Quote Link to comment https://forums.phpfreaks.com/topic/302462-how-to-point-last-element-of-an-array-in-php/#findComment-1538931 Share on other sites More sharing options...
ginerjm Posted November 4, 2016 Share Posted November 4, 2016 I need to point last element of an array You need to 'point' an element? Or 'print' an element? If it is 'print', then Pravins has 'pointed' you to a function which should help. If you truly meant 'point', I'm confused. Quote Link to comment https://forums.phpfreaks.com/topic/302462-how-to-point-last-element-of-an-array-in-php/#findComment-1538935 Share on other sites More sharing options...
Solution DeX Posted November 4, 2016 Solution Share Posted November 4, 2016 $lastItem = $yourArray[count($yourArray) - 1]; If your array has 10 items in it, you want to point to index 9 because it's a zero based array (first item is index 0). So you want to point to the count (quantity) of items in the array minus 1. Quote Link to comment https://forums.phpfreaks.com/topic/302462-how-to-point-last-element-of-an-array-in-php/#findComment-1538941 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.