Blogger Information
Blog 175
fans 1
comment 0
visits 384406
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
根据二维数组某个字段的值查找数组
dxp2tq的博客
Original
3370 people have browsed it

根据二维数组某个字段的值查找数组

/**
* @param $array
* @param $index
* @param $value
* @return mixed
*/
public function filter_by_value ($array, $index, $value){
   if(is_array($array) && count($array)>0)
   {
       foreach(array_keys($array) as $key){
           $temp[$key] = $array[$key][$index];

           if ($temp[$key] == $value){
               $newarray[$key] = $array[$key];
           }
       }
   }

   return $newarray;
}


$arr = array(
  0=>array(
       'id'=>1,
       'name'=>'a'
  ),
  1=>array(
       'id'=>2,
       'name'=>'b'
  ),
  2=>array(
       'id'=>3,
       'name'=>'c'
  ),
 3=>array(
       'id'=>4,
       'name'=>'d'
  ),
);
 
$res = filter_by_value($arr,'id',3);
print_r($res);

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post