/**
* 判断一个数组是否存在于另一个二维数组中
* $parents 二维数组
* $searched 一维数组
*/
function multidimensional_search($parents,$searched) {
if (empty($searched) || empty($parents)) {
return false;
}
foreach ($parents as $key => $value) {
$exists = true;
foreach ($searched as $skey => $svalue) {
$exists = ($exists && IsSet($parents[$key][$skey]) && $parents[$key][$skey] == $svalue);
}
if($exists){ return $key; }
}
return false;
}
demo:
$parents = array();
$parents[] = array('date'=>1320883200, 'uid'=>3);
$parents[] = array('date'=>1320883200, 'uid'=>5);
$parents[] = array('date'=>1318204800, 'uid'=>5);
echo multidimensional_search($parents, array('date'=>1320883200, 'uid'=>5)); // 1