How can arrays in PHP be used to simplify lengthy conditional statements?

When dealing with lengthy conditional statements in PHP, using arrays can simplify the code by allowing you to store the conditions and their corresponding actions in a structured way. This approach makes the code more readable and easier to maintain, as you can easily add, remove, or modify conditions without having to change the entire conditional block.

// Using arrays to simplify lengthy conditional statements
$conditions = [
    'condition1' => function() {
        // Action for condition1
    },
    'condition2' => function() {
        // Action for condition2
    },
    'condition3' => function() {
        // Action for condition3
    },
];

// Check conditions and execute corresponding actions
if (isset($conditions['condition1'])) {
    $conditions['condition1']();
} elseif (isset($conditions['condition2'])) {
    $conditions['condition2']();
} elseif (isset($conditions['condition3'])) {
    $conditions['condition3']();
} else {
    // Default action
}