Steef0w
Steef0w

Reputation: 53

Check if something is an array

Currently I have the following issue. I need to figure out how I can check if something is an array.

if(isset($_GET['koophuur']) && $_GET['koophuur'] == 'koop'){
        $this->objects->search->koop          = true;
        $this->objects->search->min_koopprijs = (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])?$_GET['min_prijs']:null);
        $this->objects->search->max_koopprijs = (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])?$_GET['max_prijs']:null);
    }elseif(isset($_GET['koophuur']) && $_GET['koophuur'] == 'huur'){
        $this->objects->search->huur          = true;
        $this->objects->search->min_huurprijs = (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])?$_GET['min_prijs']:null);
        $this->objects->search->max_huurprijs = (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])?$_GET['max_prijs']:null);
    }
    if(isset($_GET['koophuurgarage']) && $_GET['koophuurgarage'] == 'koopgarage'){
        $this->objects->search->koop          = true;
        $this->objects->search->min_koopprijs = (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])?$_GET['min_prijs']:null);
        $this->objects->search->max_koopprijs = (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])?$_GET['max_prijs']:null);
    }elseif(isset($_GET['koophuurgarage']) && $_GET['koophuurgarage'] == 'huurgarage'){
        $this->objects->search->huur          = true;
        $this->objects->search->min_huurprijs = (isset($_GET['min_prijs']) && !empty($_GET['min_prijs'])?$_GET['min_prijs']:null);
        $this->objects->search->max_huurprijs = (isset($_GET['max_prijs']) && !empty($_GET['max_prijs'])?$_GET['max_prijs']:null);
    }

I am not getting these results in my search query right now.

Upvotes: 3

Views: 133

Answers (1)

Sougata Bose
Sougata Bose

Reputation: 31749

You can use is_array function. it return true if array else false.

is_array($variable);

Also if you need to check if the array is empty or not then

empty($array) : returns true if empty.

If need to check if any key is set or not then you can use

isset($array['key']) or array_key_exists('key', $array)

is_array , array_key_exists

Upvotes: 3

Related Questions