mattm1712 Posted October 5, 2012 Share Posted October 5, 2012 $explode = explode(" ", $occurrence->Description); $score = $explode[sizeof($explodename)]; echo $score; why would this not work i am trying to eacho the last part of the string? cheers matt Link to comment https://forums.phpfreaks.com/topic/269133-echo-last-part-of-string/ Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 Because arrays start at 0, so the size of an array is 1 more than the last key. (assuming normally incremented keys like in this example, an assoc array is a whole other ballpark.) array_pop Link to comment https://forums.phpfreaks.com/topic/269133-echo-last-part-of-string/#findComment-1383044 Share on other sites More sharing options...
Psycho Posted October 5, 2012 Share Posted October 5, 2012 While I agree with Jessica's response as to why it doesn't work and how you can make it work with array_pop(), there is no reason to explode the string into an array. You can accomplish this with a simple string function: strrchr() This function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack. echo strrchr($occurrence->Description, ' '); Link to comment https://forums.phpfreaks.com/topic/269133-echo-last-part-of-string/#findComment-1383058 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.