Home  >  Article  >  Backend Development  >  How to query a value in an array in php

How to query a value in an array in php

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-19 18:01:442628browse

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.

How to query a value in an array in php

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!

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