Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 569
s4suryapal Avatar asked Mar 11 '14 05:03

s4suryapal


People also ask

How do you check if a value is not in an array JavaScript?

The Array. isArray() method checks whether the passed variable is an Array object. It returns a true boolean value if the variable is an array and false if it is not.

How do you check if an element is not in an array Java?

contains() method in Java is used to check whether or not a list contains a specific element. To check if an element is in an array, we first need to convert the array into an ArrayList using the asList() method and then apply the same contains() method to it​.

How do you check if a value is in an array?

isArray(variableName) method to check if a variable is an array. The Array. isArray(variableName) returns true if the variableName is an array. Otherwise, it returns false .

How do you check if an element is not in an array PHP?

The in_array() function is an inbuilt function in PHP that is used to check whether a given value exists in an array or not. It returns TRUE if the given value is found in the given array, and FALSE otherwise.


1 Answers

Simply

$os = array("Mac", "NT", "Irix", "Linux"); if (!in_array("BB", $os)) {     echo "BB is not found"; } 
like image 117
Elyor Avatar answered Sep 29 '22 23:09

Elyor