filter() public static method (available since version 2.0.9)
Filters array according to rules specified.
For example:
$array = [ 'A' => [1, 2], 'B' => [ 'C' => 1, 'D' => 2, ], 'E' => 1, ]; $result = \yii\helpers\ArrayHelper::filter($array, ['A']); // $result will be: // [ // 'A' => [1, 2], // ] $result = \yii\helpers\ArrayHelper::filter($array, ['A', 'B.C']); // $result will be: // [ // 'A' => [1, 2], // 'B' => ['C' => 1], // ] $result = \yii\helpers\ArrayHelper::filter($array, ['B', '!B.C']); // $result will be: // [ // 'B' => ['D' => 2], // ]
public static array filter ( $array, $filters ) | ||
---|---|---|
$array | array |
Source array |
$filters | array |
Rules that define array keys which should be left or removed from results. Each rule is:
|
return | array |
Filtered array |
Please login to continue.