3

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.

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

A blank array is also an array though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.