Re: count() & numerical arrays....
| From: | Curt Zirzow | Date: | Wed, 10 Sep 2003 04:03:26 +0000 |
| Subject: | Re: count() & numerical arrays.... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-162136@lists.php.net to get a copy of this message | ||
* Thus wrote CF High (noah@newminddesign.com):
> Hey all.
>
> Another simple, yet baffling for me, question:
>
> I have a comma delimited list of numbers; e.g. $num_list = "1,2,3,4"
>
> I split the number list to array -- $num_list_array = split("," $num_list)
>
> I then count the number of elements -- $count = count($num_list_array);
>
> I do not get 4 for $count, rather 1!
>
> I can't stand coming up with cludgy workarounds just to count the number of
> elements in a numerical list.....
So you just want to count how many digits their are?
$num_list = "1,2,3,4";
$count = substr_count($num_list, ",") + 1;
http://php.net/substr_count
No sense of all the extra work in putting it into an array.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."