2 回答
TA贡献1802条经验 获得超4个赞
您可以array_filter用来检查价格是否等于或大于 5。
<?php
$mainArray = [
"key1" => ["name" => "A", "price" => 5],
"key2" => ["name" => "B", "price" => 7],
"key3" => ["name" => "C", "price" => 2],
"key4" => ["name" => "D", "price" => 9]
];
$maxPrice = 5;
$mainArray = array_filter($mainArray, function($value) use ($maxPrice) {
return $value['price'] >= 5;
});
var_dump($mainArray);
TA贡献1825条经验 获得超6个赞
试试这个方法:
<?php
$mainArray = [
"key1" => ["name" => "A", "price" => 5],
"key2" => ["name" => "B", "price" => 7],
"key3" => ["name" => "C", "price" => 2],
"key4" => ["name" => "D", "price" => 9]
];
$min = 5;
$result = array_filter(
$array_column(mainArray, 'price'),
function ($value) use($min) {
return ($value >= $min);
}
);
- 2 回答
- 0 关注
- 134 浏览
添加回答
举报