Home  >  Article  >  php教程  >  php 查找数组键名并输出值

php 查找数组键名并输出值

WBOY
WBOYOriginal
2016-06-08 17:26:161693browse

这是一款简单的php 数组 查找实例,在数组中循环输出数组所有内容,并进来判断是否是我们要找的值并输出就OK了。

<script>ec(2);</script>

$q ='www.111cn.net';
$items = array(
"great bittern"=>"botaurus stellaris",
"little grebe"=>"tachybaptus ruficollis",
"black-necked grebe"=>"podiceps教程 nigricollis",
"little bittern"=>"ixobrychus minutus",
"black-crowned night heron"=>"www.111cn.net",
"www.111cn.net"=>"ardea purpurea",
"white stork"=>"ciconia ciconia",
"spoonbill"=>"platalea leucorodia",
"red-crested pochard"=>"netta rufina",
"common eider"=>"somateria mollissima",
"red kite"=>"milvus milvus",
"hen harrier"=>"circus cyaneus",
"heuglin's gull"=>"larus heuglini"
);
foreach ($items as $key=>$value) {
 if (strpos(strtolower($key), $q) !== false) {
  echo "$key|$value ";
 }
}

//结果为www.111cn.net|ardea purpurea

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