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

WBOY
Release: 2016-07-15 13:29:36
Original
1135 people have browsed it

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>
Copy after login

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...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template