php 如何查询数组,php
摘要 騰興網(wǎng)為您分享:php 數(shù)組查詢,完美root,途滿配貨,騰訊新聞,騰訊小說等軟件知識,以及平安證券,獵豹清理大師,奧維地圖方網(wǎng)站,我的世界天騏鉆石大陸全集,jolicloud,github手機,離線地圖包,視頻合并剪輯軟件,虛擬路由器,南京文交所,零之軌跡,html5,狂野飆車6,wifi電話,鏡頭尺寸等軟件it資訊,歡迎關(guān)注騰興網(wǎng)。php 數(shù)組查詢 * 查詢數(shù)組,如果有多個結(jié)果返回key數(shù)組 * @param array $array 操作的數(shù)組 * @param mixed $value 要查詢的值 * @return mixed */ public static function search($array, $value, $field = NULL, $once = false)...
php 數(shù)組查詢
* 查詢數(shù)組,如果有多個結(jié)果返回key數(shù)組
* @param array $array 操作的數(shù)組
* @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;
}
}
相關(guān)推薦
總結(jié)
以上是生活随笔為你收集整理的php 如何查询数组,php的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python数据集获取与基本使用(skl
- 下一篇: 面试题:找出公司员工最喜欢的k种水果