conditional - Is there a concise way to test GET parameter combinations in PHP? -
The code below examines the GET parameter, on the page there are two choices that are ordered by a type and age group. Filter.
I am exploring a method of revising the conditional which tests the type / age combination. Is this a more clear / concise way to write? // isset ($ _ request ['type']) || isset ($ _ request ['age'])) // give us some $ type = ($ _REQUEST ['type' '] ==' all '? False: (int] ($ _ request [' type ']) is required; $ Age = ($ _REQUEST [' age '] ==' all '? False: (int) ($ _ Request ['age']); // Test type of possible type / age if ($ type & age $) {$ cats = $ type} ",". $ Age;} otherwise ( $ Type) {$ cats = $ type;} Elseif ($ age) {$ cats = $ age;} and {$ cats = false;} // $ stuff with cats;} If both are ['type'] and ['age'] then "all" results will be "", that is, string (0) So it's not the same whether it's a problem or not, depending on how you use the $ cat like Editing: Oops, and another difference is I (Without special callback) e.g.
$ cat = array ($ _REQUEST ['type'] = = 'all'? False: $ (_ Request ['type']), $ _REQUEST ['age'] == 'all'? Wrong: interval ($ _ request ['age']); $ Cat = join (',', array_filter ($ Cat); eco $ cat;
if (! $ Cat)
will still work, because an empty string in a bullion reference is converted to false
If no callback is given, all entries in the input equal to FALSE (see) will be removed.
$ _ request = array ('type' => gtc; '0', 'age' => '0')
will also result in $ cat = ""
.
Is this problem in your context?
Comments
Post a Comment