我需要一些帮助才能在php中的多维数组中获取基于日期的数组元素。
这是我的数组:
Array ( [0] => Array ( [DOS] => Apr 2 2013 [Name] => Abc Starling [No] => 15616286[Duration] => 135 )
[1] => Array ( [DOS] => Apr 2 2013 [Name] => Cde Starling [No] => 15616286[Duration] => 585 )
[2] => Array ( [DOS] => Apr 3 2013 [Name] => Sdf Starling [No] => 15616286[Duration] => 123 )
[3] => Array ( [DOS] => Apr 3 2013 [Name] => Sdc Starling [No] => 15616286[Duration] => 456 )
[4] => Array ( [DOS] => Apr 4 2013 [Name] => Fcd Starling [No] => 15616286[Duration] => 789 )
[5] => Array ( [DOS] => Apr 4 2013 [Name] => Rfd Starling [No] => 15616286[Duration] => 906 )
[6] => Array ( [DOS] => Apr 5 2013 [Name] => Vfd Starling [No] => 15616286[Duration] => 567 )
[7] => Array ( [DOS] => Apr 6 2013 [Name] => Gfr Starling [No] => 15616286[Duration] => 456 )
[8] => Array ( [DOS] => Apr 6 2013 [Name] => Dvh Starling [No] => 15616286[Duration] => 343 ))
我希望今天输出Apr 3 2013
:
Array ( [0] => Array ( [DOS] => Apr 3 2013 [Name] => Sdf Starling [No] => 15616286[Duration] => 123 )
[1] => Array ( [DOS] => Apr 3 2013 [Name] => Sdc Starling [No] => 15616286[Duration] => 456 ))
答案 0 :(得分:2)
尝试array_filter
:
$source=array(array("DOS"=>"Apr 3 2013","flag"=>"hit"),array("DOS"=>"Apr 4 2013","flag"=>"no hit"),array("DOS"=>"Apr 3 2013","flag"=>"hit"));
$cond="Apr 3 2013";
$result=array_filter($source,function($v)use($cond){
return $v["DOS"]==$cond;
});
print_r($result);
答案 1 :(得分:0)
foreach($arr as $key=>$val){
if($key['DOS'] =='Apr 3 2013'){
print_r($arr[$key]);
}
}