PHP:Filtering an Array

From Progzoo
Jump to navigation Jump to search

A filter applies a test to each element - it removes any element that fails the test.

Manual loop

You can manually loop through the original list and add desired elements to the resulting list.

Return only the even numbers in the input list.


[Font] [Default] [Show] [Resize] [History] [Profile]

Using array_filter

You can also use the array_filter function.

Return only the even numbers in the input list.


[Font] [Default] [Show] [Resize] [History] [Profile]