What are the best practices for using if statements in PHP when the number of elements is not known in advance?

When the number of elements is not known in advance, it is best to use a loop (such as a foreach loop) to iterate over the elements and use if statements within the loop to perform conditional checks. This allows for dynamic handling of elements without the need to know the exact number beforehand.

$elements = array("element1", "element2", "element3");

foreach($elements as $element){
    if($element == "element1"){
        // do something
    } elseif($element == "element2"){
        // do something else
    } else {
        // default action
    }
}