检查某些东西是否为数组

时间:2016-02-09 10:04:46

标签: php arrays variables

目前我有以下问题。我需要弄清楚如何检查是否有数组。

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);
    }

我目前没有在搜索查询中获得这些结果。

1 个答案:

答案 0 :(得分:4)

您可以使用is_array功能。如果数组为true,则返回false

is_array($variable);

此外,如果你需要检查数组是否为空,那么

empty($array):如果为空则返回true

如果需要检查是否设置了任何键,则可以使用

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

is_arrayarray_key_exists