以下是一个PHP数组根据条件筛选的实例,我们将使用数组过滤函数`array_filter()`来实现。

实例描述

假设我们有一个包含学生信息的数组,每个学生对象都有一个`score`属性。我们需要筛选出所有分数大于90的学生。

实例php数组根据,PHP数组根据条件筛选实例详解  第1张

代码示例

```php

// 定义学生数组

$students = [

['name' => 'Alice', 'score' => 85],

['name' => 'Bob', 'score' => 92],

['name' => 'Charlie', 'score' => 88],

['name' => 'David', 'score' => 95],

['name' => 'Eve', 'score' => 78]

];

// 使用array_filter()筛选分数大于90的学生

$highScores = array_filter($students, function($student) {

return $student['score'] > 90;

});

// 输出结果

foreach ($highScores as $student) {

echo "