if ( array_search(array('forum_cat_id' => '100'), $cache_forums) ) {
echo 'found';
return true;
} else {
echo 'not found ';
return false;
}
--------------------------------
衷心预祝孙燕姿大陆演唱会成功!!
echo 'found';
return true;
} else {
echo 'not found ';
return false;
}
--------------------------------
衷心预祝孙燕姿大陆演唱会成功!!
$cache_forums = array
(
1 => array
(
'forum' => 'YYY'
'forum_name' => 'fff'
'forum_cat_id' => '144'
),
2 => array
(
'forum' => 'YYY'
'forum_name' => 'g'
'forum_cat_id' => '12'
),
3 => array
(
'forum' => 'YYY'
'forum_name' => 'YYY'
'forum_cat_id' => '100'
)
);
function SearchBiDimArray(&$theArray, $dimNo, $searchValue, $returnIndex = true){
if(is_array($theArray)){
$keys = array_keys($theArray[0]);
$key = $keys[$dimNo];
$elcount = count($theArray); for($i=0; $i < $elcount; $i++){
if($theArray[$i][$key] === $searchValue){
if ($returnIndex){
return $i;
}
else{
return $theArray[$i];
}
}
} }
else{
return array_search($searchValue, $theArray);
}
}$theArray = array();
$theArray[0]['firstproperty'] = 'avalue1';
$theArray[0]['secondproperty'] = 'anothervalue1';$theArray[1]['firstproperty'] = 'avalue2';
$theArray[1]['secondproperty'] = 'anothervalue2';$theArray[2]['firstproperty'] = 'avalue3';
$theArray[2]['secondproperty'] = 'anothervalue3';print SearchBiDimArray($theArray, 1, 'anothervalue2', true);
// result is 1print SearchBiDimArray($theArray, 1, 'anothervalue2', true);
// result is
//Array
//(
// [firstproperty] => avalue2
// [secondproperty] => anothervalue2
//)?>
if ( array_search(array('forum' => 'YYY', 'forum_name' => 'YYY', 'forum_cat_id' => '100'), $cache_forums) ) {
echo 'found';
return true;
} else {
echo 'not found ';
return false;
}