摘要 腾兴网为您分享:php 数组查询,完美root,途满配货,腾讯新闻,腾讯小说等软件知识,以及平安证券,猎豹清理大师,奥维地图方网站,我的世界天骐钻石大陆全集,jolicloud,github手机,离线地图包,视频合并剪辑软件,虚拟路由器,南京文交所,零之轨迹,html5,狂野飙车6,wifi电话,镜头尺寸等软件it资讯,欢迎关注腾兴网。php 数组查询 * 查询数组,如果有多个结果返回key数组 * @param array $array 操作的数组 * @param mixed $value 要查询的值 * @return mixed */ public static function search($array, $value, $field = NULL, $once = false)...
php 数组查询
* 查询数组,如果有多个结果返回key数组
* @param array $array 操作的数组
* @param mixed $value 要查询的值
* @return mixed
*/
public static function search(&$array, $value, $field = NULL, $once = false) {
$index = array();
foreach ($array as $key => $arrayValue) {
if ($field) {
if ($arrayValue[$field]==$value) {
$index[] = $key;
if ($once) {
break;
}
}
} else {
if ($value==$arrayValue) {
$index[] = $key;
if ($once) {
break;
}
}
}
}
$indexCount = count($index);
if ($indexCount<1) {
return -1;
} elseif ($indexCount==1) {
return $index[0];
} else {
return $index;
}
}
相关推荐