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

How to query a value in an array in php

醉折花枝作酒筹
Release: 2023-03-09 11:54:01
Original
2677 people have browsed it

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);
?>
Copy after login

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!

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