Home > Article > Backend Development > How to query a value in an array in php
In PHP, you can use the array_search() function to query a certain value in the array, with the syntax "array_search("element", array)"; this function searches for a key value in the array. If the specified key value is found in the array, the corresponding key name is returned; if not found, false is returned.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
<?php $a=array("a"=>"Dog","b"=>"Cat"); if(array_key_exists("a",$a)){ echo "Key exists!"; }else{ echo "Key does not exist!"; } $a=array("a"=>"Dog","b"=>"Cat","c"=>5,"d"=>"5"); echo array_search("Dog",$a); echo array_search("5",$a); ?>
Recommended: " Summary of PHP interview questions in 2021 (collection) 》《php video tutorial》
The above is the detailed content of How to query a value in an array in php. For more information, please follow other related articles on the PHP Chinese website!