1$numbers = [2, 4, 6, 8, 10];
2
3function MyFunction($number)
4{
5 return $number > 5;
6}
7
8$filteredArray = array_filter($numbers, "MyFunction");
9
10/**
11 * `$filteredArray` now contains: `[6, 8, 10]`
12 * NB: Use this to remove what you don't want in the array
13 * @see `array_map` when you want to alter/change elements
14 * in the array.
15 */
1$var = [
2 'first' => 'one',
3 'second' => null,
4 'third' => 'three',
5];
6
7
8$filteredArray = array_filter($var);
9// output: ['first'=>'one,'third'=>'three']