Adding error messages 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 &lt;ul&gt;";
    if(strpos($errorDetails, "emailInvalid") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
    if(strpos($errorDetails, "passLength") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
    if(strpos($errorDetails, "passLowerCase") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
    if(strpos($errorDetails, "passUpperCase") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
    if(strpos($errorDetails, "passNumberSymbol") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
    if(strpos($errorDetails, "passMatch") !== false){
        $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
    }
$errorList .= "&lt;/ul&gt;";
echo $errorList;
I would use an associative array (also known as  a "map" or "dictionary" in other languages).

$errorMessages = array('emailInvalid' =&gt; 'Invalid email',
    'passLength' =&gt; 'invalid password length',
    'passLowerCase' =&gt; 'missing lower case character in password'
    // and so on...
); 


Then I would loop across this map:

foreach ($errorDetails as $key =&gt; $value) {
    if (strpos($errorDetails, $key) !== false) {
        $errorList .= '&lt;li&gt;' . $value . '&lt;/li&gt;';
    }
}


strpos

Storing your error-message stubs in $errorDetails is inefficient. strpos loops through the string each time. I'd recommend to instead append your error messages to an array, which would open up the possibility of looking up the full error message from something like emailInvalid with a O(1) complexity.

How did I know it was a map that was needed?

Let's look at this code:

if(strpos($errorDetails, "emailInvalid") !== false){
    $errorList .= "&lt;li&gt;Some text&lt;/li&gt;";
}
if(strpos($errorDetails, "passLength") !== false){
    $errorList .= "&lt;li&gt;Some (other) text&lt;/li&gt;";
}


There are two things that differs here, these parts can be simplified to:

if (strpos($errorDetails, $xxxxxxx) !== false) {
    $errorList .= $yyyyyyy;
}


To clean up this code, we could extract a method and call that multiple times, such as:

addErrorList($errorDetails, 'emailInvalid', 'invalid e-mail');
addErrorList($errorDetails, 'passLength', 'invalid password length');
...


However, this is still not very nice. A map / associative array contains a key to value mapping, which is precisely what you have here. For each specific error detail key, there is an associated error message. So add those values to an associative array and then loop through it.