//一維搜索
//$SeAry = $ObjVoteMod->ArraySearchInt('100003865712991',$ObjVoteMod->SetMemcache($Str_Ary_List));
//(撈取數,撈取陣列) return IntKey;
//預設A 模式 回傳陣列[0]取的單一值 B模式 自動計算陣列上下頁功能 回傳陣列 裡面有預設三個數據
public function ArraySearchInt($InData,$Inarry,$model="A")
{
if($Inarry!=NULL){
$IntRt=NULL;
foreach ($Inarry AS $nkey => $nvalue):
if($nvalue == $InData){
$IntRt[] = $nkey;
}
endforeach;
if($IntRt){
if($model == "B"){
$IntRt[0] == 0? $FastData = 0:$FastData = $IntRt[0]-1;
$IntRt[0] ==count($Inarry)-1? $NextData = count($Inarry)-1:$NextData=$IntRt[0]+1;
$arr_RtData = array(
"Fast"=>$FastData, //上一筆
"0"=>$IntRt[0],
"Next"=>$NextData);
return $arr_RtData;
}else{
return $IntRt; //回傳單一值陣列
}
}else{
return $IntRt=NULL;
}
}else{
return $IntRt=NULL;
}
}
//二維陣列搜索
//$IntRt = $objTools->ArraySearch(array('ID'=>$this->_request->get('id')),$this->view->intData);
//(撈取陣列,撈取基準陣列) return IntKey;
public function ArraySearch($needle, $haystack) {
if(empty($needle) || empty($haystack)) {return false;}
foreach ($haystack as $key => $value){
$exists = 0;
foreach ($needle as $nkey => $nvalue) {
if (!empty($value[$nkey]) && $value[$nkey] == $nvalue) {
$exists = 1;
}else{
$exists = 0;
}
}
if ($exists) return $key;
}
return false;
}
2012年7月18日 星期三
PHP-Ary搜索
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言