-1

At first I posted my code:

//if ($filterResults['id']) {
  if (isset($filterResults['id'])){
            $select = $this->select();
            $select->where('id = ?', $filterResults['id']);

        $this->fetchAll($select);


        }

Now, the problem is if I use if ($filterResults['id']) { it gives the expected result but if I use if (isset($filterResults['id'])){ it doesn't work. I don't see any reason behind this.

rid
  • 61,078
  • 31
  • 152
  • 193
user1559230
  • 2,790
  • 5
  • 26
  • 32

2 Answers2

4

isset() will return false if the value is NULL. If this is a possibility you may wish to use array_key_exists() instead:

if (array_key_exists('id', $filterResults)) {
    [...]
}
Tim Fountain
  • 33,093
  • 5
  • 41
  • 69
0

It works if I use the isset() like this:

if ( isset($filterResults['id']) && $filterResults['id'] != null ){
        $select = $this->select();
        $select->where('id = ?', $filterResults['id']);

    $this->fetchAll($select);


    }
user1559230
  • 2,790
  • 5
  • 26
  • 32