Home > Backend Development > PHP Tutorial > Array array 'find' operation

Array array 'find' operation

WBOY
Release: 2016-08-08 09:31:34
Original
1101 people have browsed it

1. Whether an element exists in the array:

echo '<br/>数组的操作1:in_array($value,$array,$type)';
//$type:是否对$value的值进行类型匹配 true/false,默认值是 false 
$arr=array("name"=>"DOOR",32);
(in_array("32",$arr))? $v="存在" : $v= "不存在";
echo "<br/>".$v;
Copy after login

Code running result:

数组的操作1:in_array($value,$array,$type)
存在
Copy after login

2. Whether the specified key value exists in the array:

echo '<br/>数组的操作2:array_key_exists($key,$array)';
//元素32的键值是0,查找的键值是“0”,没有严格的类型匹配
$arr=array("name"=>"DOOR",32);
if (array_key_exists("0",$arr)){
	echo "<br/>存在";
}
Copy after login

Code running result:

数组的操作2:array_key_exists($key,$array)
存在
Copy after login

Summary: in_array and array_key_exists matching are case-sensitive.

The above introduces the array 'search' operation, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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