Ec (2); php array query & nbsp; * query the array. If multiple results exist, return the key array & nbsp; * @ paramarray $ array Operation array & nbsp; * @ parammixed $ value the value to be queried & nbsp; * @ returnmixed & nbsp; * & nbsp; publicstaticfunctionsearch (& amp; $ array script ec (2); script
Php array Query
* Query the array. If multiple results are returned, the key array is returned.
* @ Param array $ array Operation array
* @ Param mixed $ value the value to be queried
* @ 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;
}
}