Home > php教程 > php手册 > 如何运用PHP函数count()求出数组的长度

如何运用PHP函数count()求出数组的长度

WBOY
Release: 2016-06-13 11:06:39
Original
846 people have browsed it

新学int count ( mixed var)

返回 var 中的单元数目,通常是一个 array(任何其它类型都只有一个单元)。

如果 var 不是数组类型,将返回 1(例外:count(NULL) 的结果是 0)。

警告

PHP函数count()对没有初始化的变量返回 0,但对于空的数组也会返回 0。用 isset() 来测试变量是否已经初始化。

例子 1. count() 例子

<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>
<li class=""><span>$vegetables[0] = "corn";  </span></li>
<li class="alt"><span>$vegetables[1] = "broccoli";  </span></li>
<li class=""><span>$vegetables[2] = "zucchini";  </span></li>
<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>
</li>
<li class=""><span>echo $text;  </span></li>
<li class="alt">
<span></span><span class="tag"><strong><font color="#006699">?></font></strong></span><span> </span><span></span>
</li>
</ol>
Copy after login

有时如果不知道PHP函数count()的话,使用笨方法:select count(*)from table


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template