if($_GET['category'] === "all") { //stuff }This only works if it's exactly "all" what if I want to run the code even if it's "ALL" or "aLl" or "aLL".
I'm hoping there is a better way than doing a bunch of || in the if statement
if($_GET['category'] === "all") { //stuff }This only works if it's exactly "all" what if I want to run the code even if it's "ALL" or "aLl" or "aLL".
if(strtolower($_GET['category']) === "all") { //stuff }?
$word1 = 'test'; $word2 = 'Test'; if ( strcasecmp($word1, $word2) === 0 ) { echo 'They are the same!'; }
Now what if you had a different word? For a three-letter word, there are only eight different combinations. However, even if you have only an eight-letter word, you already have 256 combinations! Ten letters? 1024 combinations!Maybe create an array containing allowed forms of "all", then use the in_array function.
Unless you use strtolower before checking it, or that other thing you posted.Tino wrote:Now what if you had a different word? For a three-letter word, there are only eight different combinations. However, even if you have only an eight-letter word, you already have 256 combinations! Ten letters? 1024 combinations!
Seems like that would get way too tedious
$word = 'aLL'; $combinations = array('all', 'All', 'aLl', 'alL', 'ALl', 'AlL', 'aLL', 'ALL'); if ( in_array(word, $combinations) ) { echo "It's good!"; }Which in itself is a fine solution, but, as I said, way too tedious for longer words. I mean, I don't really want to create a 1024 item long array with all different ways to write 'homeless' or something.