这篇文章主要介绍了php检测数组长度函数sizeof与count用法,实例分析了count的用法,并对sizeof函数进行了详尽的分析说明,具有一定的参考借鉴价值,需要的朋友可以
本文实例讲述了php检测数组长度函数sizeof与count用法。分享给大家供大家参考。具体如下:
在php检测数组长度的函数有sizeof count 下面看个简单实例:
复制代码 代码如下:
$colorlist = array("apple"=>"red", "grass"=>"green","sky"=>"blue","night"=>"black","wall"=>"white");
echo "数组长度为: ".count($colorlist); //5
count:count() 函数计算数组中的单元数目或对象中的属性个数,对于数组,返回其元素的个数,对于其他值,,返回 1,如果参数是变量而变量没有定义,则返回 0,如果 mode 被设置为 count_recursive(或 1),则会递归底计算多维数组中的数组的元素个数.
sizeof:定义和用法,sizeof() 函数计算数组中的单元数目或对象中的属性个数.
语法:sizeof(array,mode)
参数 描述
array 必需,规定要计数的数组或对象.
mode
可选,规定函数的模式,可能的值:
0 - 默认.不检测多维数组,数组中的数组.
1 - 检测多维数组。
注释:参数mode是 php 4.2 中加入的.
提示 count sizeof
注释:当变量未被设置,或是变量包含一个空的数组,该函数会返回 0,可使用 isset() 变量来测试变量是否被设置.
希望本文所述对大家的PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft