如何检查不在数组元素中 [英] How to check not in array element
本文介绍了如何检查不在数组元素中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查一个元素是否不在数组中而不是想重定向页面:我的代码如下:
I am trying to check if an element is not in array than want to redirect page: My code is as below:
$id = $access_data['Privilege']['id'];
if(!in_array($id,$user_access_arr))
{
$this->Session->setFlash(__('Access Denied! You are not eligible to access this.'), 'flash_custom_success');
return $this->redirect(array('controller'=>'Dashboard','action'=>'index'));
}
我很困惑如何检查元素是否不在数组中.因为我们可以使用 PHP 的 in_array
函数检查数组中是否存在元素.我正在尝试使用 (!in_array)
来检查它,但我没有得到结果.
I am confused how to check if element is not in array.
As we can check element exist or not in array using in_array
function of PHP.
I am trying to check it using (!in_array)
but I did not got result.
推荐答案
简单
$os = array("Mac", "NT", "Irix", "Linux");
if (!in_array("BB", $os)) {
echo "BB is not found";
}
这篇关于如何检查不在数组元素中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文