php数组是否存在指定字符与数组长度检测实例
本教程只讲了二个地方一个是利用数组函数in_array 检查数组中是否存在指定字符串,与利用count函数来判断数组长度。定义和用法
本教程只讲了二个地方一个是利用数组函数in_array 检查数组中是否存在指定字符串,与利用count函数来判断数组长度。
定义和用法
in_array() 函数在数组中搜索给定的值。
语法
in_array(value,array,type)
*/
$os_list=array("mac","nt","irix","linux"); //定义数组
if(in_array("irix",$os_list)) //检查数组中是否存在lrix
{
echo "当前操作系统列表中存在lrix"; //如果存在,输出内容
}
echo "
";
if(!in_array("mac",$os_list))
{
echo "当前操作系统列表中不存在mac"; //区分大小写所以该句不会被执行
}
/*
in_array 如果给定的值 value 存在于数组 array 中则返回 true。如果第三个参数设置为 true,函数只有在元素存在于数组中且数据类型与给定值相同时才返回 true。
如果没有在数组中找到参数,函数返回 false。
注释:如果 value 参数是字符串,且 type 参数设置为 true,则搜索区分大小写。
定义和用法
语法
count(array,mode)
count() 函数计算数组中的单元数目或对象中的属性个数。
对于数组,返回其元素的个数,对于其他值,返回 1。如果参数是变量而变量没有定义,则返回 0。如果 mode 被设置为 count_recursive(或 1),则会递归底计算多维数组中的数组的元素个数。
//数组长度
*/
$a[0]=1; //通过分别赋值,建立一个数组$a[]
$a[1]=3;
$a[2]=5;
$result=count($a); //返回数组$a的元素个数3
echo $result;
echo "
";
$b[0]=7;
$b[5]=9;
$b[10]=11;
$result=count($b); //返回数组$b的元素个数3
echo $result;
echo "
";
$result=count(null); //返回0
echo $result;
echo "
";
$result=count(false); //返回1
echo $result;
/*
提示和注释
注释:当变量未被设置,或是变量包含一个空的数组,该函数会返回 0。可使用 isset() 变量来测试变量是否被设置。

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

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
