Multiple if statements in a row do not work?

So I put this into my script

if (!isset($params['q']) || !$params['q']) {
    $params['q'] = 'trending';
}


if (!isset($params['meal']) || !$params['meal']) {
    $params['meal'] = 0;
}

if (!isset($params['sort']) || !$params['sort']) {
    $params['sort'] = 0;
}

    $params = array_unique($params);

Now the weird thing that happens is $params['q'] = 'trending' and $params['meal'] = 0 but suspiciously the sort will be dropped out altogether. If I put sort ahead of meal, instead of meal showing up sort will show up. If I put sort after another command then all three will list. Is there something I am missing here? It seems as if, in php, I cannot do more than two if statements in a row?

    array (size=2)
    'q' => string 'trending' (length=8)
    'meal' => int 0

This is with out changing order, now if I were to put a command between if statement 2 and 3 I get

    array (size=3)
    'q' => string 'trending' (length=8)
    'meal' => int 0
    'sort' => int 0

Which is what I want

Answers


Aren't you trying to see if the key exists at all? If so, you may want to use array_key_exists, like this:

if (!array_key_exists('q', $params)) {
    $params['q'] = 'trending';
}

if (!array_key_exists('meal', $params) {
    $params['meal'] = 0;
}

if (!array_key_exists('sort', $params) {
    $params['sort'] = 0;
}

$params = array_unique($params);

Need Your Help

Dynamic scaffolding of multiple domain classes with single controller

grails-2.0 grails-plugin grails-domain-class grails-controller

For my web application in grails I have 3 admin controlling domain classes and no need of special UIs. For this I have decided to use dynamic scaffolding.

Pgadmin III Alternative - Windows

windows postgresql er-diagrams

I am looking for an alternative to the free pgAdmin III that works on windows. I basically need it for managing my tables / views / SP / etc. If it did ER diagrams, that is a huge plus, and I lik...