I am new to PHP and was just wondering if there is a better way to write the following OR if it would make any difference to use elseif here instead of multiple if statements - especially if the options in questions might be more than in the example here (the current code is working).
Note: I cannot use switch here since the haystack string can contain multiple of the needle strings.
$errorList .= "Some text <ul>";
if(strpos($errorDetails, "emailInvalid") !== false){
$errorList .= "<li>Some text</li>";
}
if(strpos($errorDetails, "passLength") !== false){
$errorList .= "<li>Some text</li>";
}
if(strpos($errorDetails, "passLowerCase") !== false){
$errorList .= "<li>Some text</li>";
}
if(strpos($errorDetails, "passUpperCase") !== false){
$errorList .= "<li>Some text</li>";
}
if(strpos($errorDetails, "passNumberSymbol") !== false){
$errorList .= "<li>Some text</li>";
}
if(strpos($errorDetails, "passMatch") !== false){
$errorList .= "<li>Some text</li>";
}
$errorList .= "</ul>";
echo $errorList;
<li>Some text</li>is not, or will not be, your real code. As noted in the help center, Code Review prefers real code. \$\endgroup\$