简体   繁体   English

php isset shorthand else返回数组无效

[英]php isset shorthand else return array not working

I have this php code line 我有这个PHP代码行

$data['viewData']['filter'] = isset($parameters['filter']) ? $parameters['filter'] : array('filter1', 'filter2', 'filter3', 'filter4');

Is something wrong with the isset shorthand because when I print_r($data['viewData']['filter'] with else being active, returns nothing/null/empty. isset速记有问题,因为当print_r($data['viewData']['filter']并且其他处于活动状态时,不返回/ null / empty。

What could be wrong? 可能有什么不对?

Edit, to add more info: 编辑,添加更多信息:

Code inside the controller: 控制器内的代码:

if (isset($parameters['filter']))
{
    $data['viewData']['filter'] = $parameters['filter'];
}
else
{
    $data['viewData']['filter'] = array('filter1', 'filter2', 'filter3', 'filter4');              
}
$data['viewData']['query']   = $parameters['search'];
$data['viewData']['results'] = $searchResults;
$data['view'] = 'searchResults';
$this->load->view('includes/template', $data);

Code inside view: 代码内部视图:

prePrint($viewData['apis']);

And I get nothing when the else enters 当别人进入时,我什么也得不到

Codeigniter is used as framework * prePrint is just a custom function that contains <pre> and print_r(); Codeigniter用作框架* prePrint只是一个包含<pre>print_r();的自定义函数print_r();

I don't really understand what you mean by it returns "nothing/null/empty" since a variable cannot return all 3 of those at once. 我真的不明白你的意思是它返回“nothing / null / empty”,因为变量不能同时返回所有这3个。 isset doesn't check to see if any data exists, it only checks to see if the variable or array index is set, so if you have to make sure it's set and also contains data, you'll want to try this: isset不检查是否存在任何数据,它只检查是否设置了变量或数组索引,所以如果你必须确保它已经设置并且还包含数据,你需要尝试这样做:

if (isset($parameters['filter']) && $parameters['filter'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM