Home  >  Article  >  Backend Development  >  PHP uses array_search function to implement array search_PHP tutorial

PHP uses array_search function to implement array search_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:50:471036browse

How PHP uses the array_search function to implement array search

The example in this article describes how PHP uses the array_search function to implement array search. Share it with everyone for your reference. The specific implementation method is as follows:

1

2

3

4

5

6

7

8

9

$array = array(4,5,7,8,9,10);

$found = array_search(8, $array);

//调用array_search函数并输出查找结果

if($found) //如果找到输出键

echo "已找到,键为".$found;

else //如果没有找到输出错误信息

echo "没有找到";

?>

1 2

3

4

5

7 8 9
$array = array(4,5,7,8,9,10);

$found = array_search(8, $array);
//Call the array_search function and output the search results
<🎜>if($found) //If the output key is found<🎜> <🎜>echo "Found, key is ".$found;<🎜> <🎜>else //If not found, output error message<🎜> <🎜>echo "not found";<🎜> <🎜>?>
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/1015880.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1015880.htmlTechArticleHow PHP uses the array_search function to implement array search. This example describes how PHP uses the array_search function to implement array search. Share it with everyone for your reference. Specific implementation method...
Statement:
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