-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 に答える