How do I count numbers with php
$mynumbers="0855 468 4864 63848 1486"; //This is my variable, the pattern has to be like this, each number is separated by a space.
echo "There are 5 numbers in your variable";
It should return:
5
How do I do that, I know there's str_word_count
but it only counts words not numbers.
ignorethis 123 andthis
) then you could loop through each item in the result and increment a counter if they are considered to be numeric.$exploded = explode(' ', $mynumbers); echo 'There are '.count($exploded).' numbers in your variable.';