Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 464
Steef0w Avatar asked Sep 25 '26 06:09

Steef0w


1 Answers

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

like image 117
Sougata Bose Avatar answered Sep 27 '26 21:09

Sougata Bose



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!