xProteuSx Posted October 14, 2011 Share Posted October 14, 2011 I remember doing this over a year ago, but now I've completely forgotten how to do this, and I'd much appreciate some pointers: I have a string as follows: 12|445|3|321|88|2 I'd like to do 2 things: First, I'd like to count the number of numbers (6 in this case: 12, 445, 3, 321, 88, 2); Then I'd like to enter them into an array. How do I go about this? Please help ... Quote Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/ Share on other sites More sharing options...
Nodral Posted October 14, 2011 Share Posted October 14, 2011 It'd be easier to do it the other way round $array=explode("|",$string); echo count($array); Quote Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/#findComment-1279295 Share on other sites More sharing options...
salathe Posted October 14, 2011 Share Posted October 14, 2011 Nodral, did you mean to use array_sum() instead of count()? Quote Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/#findComment-1279296 Share on other sites More sharing options...
Nodral Posted October 14, 2011 Share Posted October 14, 2011 No, to count the number of entries as per the post, use count(). To add the entries in an array uses array_sum() The question was to see how many values there were. Quote Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/#findComment-1279297 Share on other sites More sharing options...
xProteuSx Posted October 14, 2011 Author Share Posted October 14, 2011 You guys are awesome! Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/#findComment-1279471 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.