legohead6 Posted January 26, 2008 Share Posted January 26, 2008 ok, i have a script that finds out a file name in a directory, then it echos it to the user, but the file may be in different sub directories or in the root, so i exploded it by / now i just need a function to get the last value of the array(which would be the direct file name). is there such a function? or do i need to use if emptys? Quote Link to comment https://forums.phpfreaks.com/topic/87952-solved-last-value-in-array/ Share on other sites More sharing options...
papaface Posted January 26, 2008 Share Posted January 26, 2008 $lastnum = count($array) - 1; echo $array[$lastnum]; Quote Link to comment https://forums.phpfreaks.com/topic/87952-solved-last-value-in-array/#findComment-449971 Share on other sites More sharing options...
Barand Posted January 26, 2008 Share Posted January 26, 2008 <?php $str = 'abc/def/ghi/filename'; $arr = explode ('/', $str); echo end($arr); // --> filename ?> Quote Link to comment https://forums.phpfreaks.com/topic/87952-solved-last-value-in-array/#findComment-449973 Share on other sites More sharing options...
legohead6 Posted January 26, 2008 Author Share Posted January 26, 2008 cool! thanks, both methods work.. Quote Link to comment https://forums.phpfreaks.com/topic/87952-solved-last-value-in-array/#findComment-449985 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.