-3

我需要一些帮助来获取 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 )) 
4

2 回答 2

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);

现场演示


编辑:您的阵列上的现场演示

于 2013-04-19T09:14:39.663 回答
0
foreach($arr as $key=>$val){
if($key['DOS'] =='Apr 3 2013'){
print_r($arr[$key]);
}
}
于 2013-04-19T09:15:04.557 回答