// 二维数组中搜索满足条件的数组
// $twoDim = false 时搜索一维数组
function _array_search($haystack, $condition = '', $limit = 0, $twoDim = true) {
if (!$condition) {
return $haystack;
} if ($twoDim) {
$replaceFrom = array (
"|(\w+)[ ]*\!=|im",
"|(\w+)[ ]*[=]+|im",
"|(\w+)[ ]*>|im",
"|(\w+)[ ]*<|im", "| and |im",
"| or |im",
"| not |im",
"/(\w+)[ ]*like[ ]*['|\"]%([^|]*)%['|\"]/ims",

);
$replaceTo = array (
'$item[\'\1\'] !=',
'$item[\'\1\'] ==',
'$item[\'\1\'] >',
'$item[\'\1\'] <', ' && ',
' || ',
' ! ',
'strstr ( strtolower ( $item[\'\1\'] ), strtolower ( "\2" ) ) != ""',

); $condition = preg_replace($replaceFrom, $replaceTo, $condition);
} while (list ($key, $item) = @ each($haystack)) {
$con = $condition;
$matched = false; if ($twoDim) {
@ eval ("\$con = $con;");
if (is_bool($con)) {
$matched = $con;
}
} else {
$matched = ($item == $condition);
} if ($matched) {
$arrayReturn[$key] = $item;
} if ($limit > 0 && count($arrayReturn) >= $limit) {
break;
}
}
return $arrayReturn;
}