[英]Whats the best way to filter below multidimentional array in PHP
我想要pubsite_id = 8的所有數組是什么? 我可以使用foreach來做到這一點,但是當它變得更大時,它似乎非常昂貴。
array(
array( "startdate" => "2014-02-01",
"enddate" => "2014-02-13",
"pubsite_id" => "1",
"dfp_order_id" => "116260016",
"amount" => "-5000.00000",
"amountperday" => -384.61538461538
),
array( "startdate" => "2014-02-01",
"enddate" => "2014-02-28",
"pubsite_id" => "8",
"dfp_order_id" => "116260016",
"amount" => "-700.00000",
"amountperday" => -25
),
...
)
根據@deceze的建議, array_filter
是一種不錯的方法,它的性能和其他任何東西一樣好:
$filtered_arr = array_filter( $arr, function( $item ) {
return $item["pubsite_id"] == "8";
} )
foreach($array as $value)
{
foreach($value as $key => $val)
{
if($val['pubsite_id'] == "8")
{
/*your stuff */
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.