检查某物是不是为数组
Posted
技术标签:
【中文标题】检查某物是不是为数组【英文标题】:Check if something is an array检查某物是否为数组 【发布时间】:2016-05-19 06:19:12 【问题描述】:目前我有以下问题。我需要弄清楚如何检查某个东西是否是一个数组。
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】:您可以使用is_array
函数。如果数组则返回true
,否则返回false
。
is_array($variable);
如果你需要检查数组是否为空,那么
empty($array)
:如果为空,则返回 true
。
如果需要检查是否设置了任何键,则可以使用
isset($array['key'])
或 array_key_exists('key', $array)
is_array , array_key_exists
【讨论】:
空数组也是数组以上是关于检查某物是不是为数组的主要内容,如果未能解决你的问题,请参考以下文章