Try this instead:
PHP Code:
$incoming = "Letterform, Wordmark,Someoldcrap";
$allowed = array("Letterform","Wordmark", "Pictorial", "Emblem", "Abstract");
$types = explode(",",$incoming);
$results = ""; // declare the empty string
// as was pointed out get used to writing "foreach plural as singular" and you wont get mixed up
foreach($types as $type) {
if( in_array(trim($type), $allowed)){
$results .= strtolower($type) . '.jpg for ' . $type . PHP_EOL; // concat the string
}
}
echo $results;
Your original code was flawed because you were forever overwriting any previous match.
This code concatenates a string, but could just as easily be returning an array.
PHP Code:
if($types = 'Pictorial') {
$l = 'pictoral.jpg';
}
When you see yourself writing things over and again Pictorial, pictorial alarm bells should go off in your head and you should ask "is there a better way?" Perhaps invest some real time in grokking how arrays work.
EDIT Gah, too slow, beaten by JB!
Bookmarks