i want to list only certain categories that are in the database. if ($category['name'] == "cat1") PHP: what is the right syntax to add cat2?
Would an ElseIf be what your looking for? if ($category['name'] == "cat1"){ ;; }else if ($category['name'] == "cat2"){ ;; }else if ($category['name'] == "cat3"){ ;; } PHP: That is more than one If statment. But I think that a Switch might be a better choice: switch($category['name']){ case "cat1": //Do stuff break; case "cat2": //Do more stuff break; case "cat3": //Etc break; default: //if none of the conditions are met do this. } PHP: Otherwise if you are looking to test two conditions then: if ($category['name'] == "cat1" || $category['name'] == "cat2"){ //Do stuff. } PHP: (Will execute if either one is true, or: ) if ($category['name'] == "cat1" && $category['name'] == "cat2"){ //Do stuff. } PHP: (Will execute only if both are true.)
thats the one i was looking for. i knew the way it should be,but i couldn't remember the way it is coded. thanks.
If this is going to change often and/or get more complex, use an array or regex instead of hard coding each individual case. Array: if (in_array($category['name'], array('cat1', 'cat2')) { PHP: Regex: if (preg_match('/cat[12]/', $category['name'])) { PHP: