What are some alternative approaches to using if/else statements with arrays in PHP?

When working with arrays in PHP, using if/else statements to check for specific conditions can become cumbersome and repetitive. An alternative approach is to use array functions like array_filter() or array_map() to perform operations on array elements based on certain criteria. These functions can help simplify the code and make it more readable.

// Example using array_filter() to filter elements based on a condition
$numbers = [1, 2, 3, 4, 5];
$filteredNumbers = array_filter($numbers, function($number) {
    return $number % 2 == 0; // Filter even numbers
});

print_r($filteredNumbers);