B
B
Boris Yakushev2015-09-24 10:45:55
PHP
Boris Yakushev, 2015-09-24 10:45:55

Counting the number of values ​​in an array row?

Good afternoon. I output an array with a while loop, the array has such a line $sname = $row['sname'];
. In it, the values ​​are listed separated by commas, but how to count the number of values ​​in this line?
Using the count() function; did not help.
update 1.1 counting the number of commas is not suitable, for example, the field can be empty, or with one value, in both cases there will be no comma.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry Kim, 2015-09-24
@za4me

$count = count(explode(',', $str));

D
Dmitry Evgrafovich, 2015-09-24
@Tantacula

Count the number of commas in a string+1

M
Maxim E, 2015-09-24
@creativeworm

Count the number of rows matching the query:

SELECT COUNT(column_name) FROM table_name;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question