当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > sizeof() 函数

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 sizeof() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 459 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The sizeof() function counts the elements of an array, or the properties of an object.
sizeof()函数的作用是:统计一个数组中所包含的元素数量;或者是统计一个对象中所包含的属性数量。

This function is an alias of the count() function.
sizeof()函数是count()函数的替代函数。

Syntax
语法

sizeof(array1,array2)

Parameter
参数
Description
描述
array Required. Specifies the array or object to count.
必要参数。指定需要被统计数量的函数或对象
mode Optional. Specifies the mode of the function. Possible values:
 可选参数。指定执行模式。下面列出可使用的参数:
  • 0 - Default. Does not detect multidimensional arrays (arrays within arrays)
    0 – 默认值。不对多位数组进行操作(数组中包含数组)
  • 1 - Detects multidimensional arrays
    1 – 对多位数组进行操作

Note: This parameter was added in PHP 4.2
注意:仅在PHP 4.2版本以上支持该函数



Tips and Notes
注意点

Note: This function may return 0 if a variable isn't set, but it may also return 0 if a variable contains an empty array. The isset() function can be used to test if a variable is set.
注意:如果变量不存在或者变量为空值,那么该函数都将返回“0”。Isset()函数可以用来测试变量是否存在。
 


Example
案例

<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
$result = sizeof($people);
echo $result;
?>

The output of the code above will be:
上述代码将输出下面的结果:

4

评论 (0) All

登陆 | 还没注册?