Question: I have the follwing code:

```
switch ((int)$_GET["loanprovider"]) {
    case ((int)$_GET["loanprovider"] > 1):
        $sql_loanprovider1a = " l.id in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
        $sql_loanprovider1b = " l.loanid in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
        break;
    default:
        break;
}

```

If i run the page without setting LOANPROVIDER in the URL, the SWITCH still enters the first case and not the DEFAULT. How come??

/Bob

Answer: 
The explanation is quite simple:

```
var_dump( (int)$_GET["loanprovider"]  );
var_dump( (int)$_GET["loanprovider"] > 1 );

```

The output is:

```
int(0)
bool(false)

```

They're both the same (the integer 0 (zero) is considered as `FALSE`), and case 1 will always get executed if the query parameter `loanprovider` is empty.

Refer to the [PHP Manual](http://php.net/manual/en/types.comparisons.php) for more information.

---

And, to actually fix the issue, use [`isset()`](http://php.net/isset). It's also a good idea to declare variables and store values if you need to re-use it later.

The following looks neater, in my opinion, and it works (tested):

```
if(isset($_GET['loanprovider'])) 
{
    $value = (int)$_GET["loanprovider"];
    switch ($value) {
        case ($value > 1):
            $sql_loanprovider1a = " l.id in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
            $sql_loanprovider1b = " l.loanid in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
            break;
        default:
            break;
    }
}

```

For debugging the issue, you can always use [`var_dump`](http://php.net/var_dump).
I would first check if $\_GET["loanprovider"] is set because if you don't set loanprovider in the url it will be undefined and undefined does not have to be "0" it can be something else. In this case it would be probably some value that makes your statement ((int)$\_GET["loanprovider"] > 1): true.

The correct code would be:

```
if (isset((int)$_GET["loanprovider"]))
{
  switch ((int)$_GET["loanprovider"]) {
    case ((int)$_GET["loanprovider"] > 1):
        $sql_loanprovider1a = " l.id in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
        $sql_loanprovider1b = " l.loanid in (select la.loanid from loan_approvals la where la.bankid = ".$_GET["loanprovider"].") and";
        break;
    default:
        break;
  }
}  

```