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? 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]; 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 ?> 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.. 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
Archived
This topic is now archived and is closed to further replies.