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 ... 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); 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()? 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. 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. Link to comment https://forums.phpfreaks.com/topic/249110-parsing-a-string/#findComment-1279471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.