Home  >  Article  >  Backend Development  >  How to use the PHP function count() to find the length of an array_PHP Tutorial

How to use the PHP function count() to find the length of an array_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:29:361126browse

New Learningint count (mixed var)

Returns the number of cells in var, usually an array (any other type has only one cell).

If var is not an array type, 1 will be returned (exception: the result of count(NULL) is 0).

Warning

The PHP function count() returns 0 for uninitialized variables, but also returns 0 for empty arrays. Use isset() to test whether a variable has been initialized.

Example 1. count() example

<ol class="dp-xml"><li class="alt">
<span><strong><font color="#006699"><span class="tag"><?</SPAN><SPAN class=tag-name>php</SPAN></FONT></STRONG><SPAN> </SPAN></SPAN><LI class=""><SPAN>$vegetables[0] = "corn";  </SPAN><LI class=alt><SPAN>$vegetables[1] = "broccoli";  </SPAN><LI class=""><SPAN>$vegetables[2] = "zucchini";  </SPAN><LI class=alt><SPAN>$</SPAN><SPAN class=attribute><FONT color=#ff0000>text</FONT></SPAN><SPAN> = </SPAN><SPAN class=attribute-value><FONT color=#0000ff>implode</FONT></SPAN><SPAN>(",", $vegetables);  </SPAN></SPAN><LI class=""><SPAN>echo $text;  </SPAN><LI class=alt><SPAN></SPAN><SPAN class=tag><STRONG><FONT color=#006699>?></span></font></strong></span><span> </span><span></span>
</li></ol>

Sometimes if you don’t know the PHP function count(), use the stupid method: select count(*) from table


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446363.htmlTechArticleNew learning int count (mixed var) Returns the number of units in var, usually an array (any other type Only one unit). If var is not an array type, 1 will be returned (exceptions...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn