如何在PHP中不检查数组元素 [英] How to check not in array element in php
本文介绍了如何在PHP中不检查数组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查元素是否不在数组中而不是要重定向页面: 我的代码如下:
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";
}
这篇关于如何在PHP中不检查数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文