Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php check if any of multiple values in array

function in_array_any($needles, $haystack) {
   return !empty(array_intersect($needles, $haystack));
}

echo in_array_any( [3,9], [5,8,3,1,2] ); // true, since 3 is present
echo in_array_any( [4,9], [5,8,3,1,2] ); // false, neither 4 nor 9 is present
Comment

in array php multiple values

$haystack = array(...);

$target = array('foo', 'bar');

if(count(array_intersect($haystack, $target)) == count($target)){
    // all of $target is in $haystack
}

if(count(array_intersect($haystack, $target)) > 0){
    // at least one of $target is in $haystack
}
Comment

PREVIOUS NEXT
Code Example
Php :: install laravel in bootstrap 8 
Php :: laravel create new migration 
Php :: laravel chunk select 
Php :: php array append 
Php :: print variable php 
Php :: php do while loop 
Php :: delete route method in laravel 
Php :: is dir php 
Php :: Unable to create PsySH runtime directory. Make sure PHP is able to write to /run/user in order to continue. 
Php :: php to list files 
Php :: run a php site 
Php :: eloquent limit 
Php :: push key value array php 
Php :: add css to gutenberg editor 
Php :: laravel htaccess 
Php :: php conditionally remove element from array 
Php :: wordpress get local date 
Php :: laravel create project with auth 2021 
Php :: how to create config file in php 
Php :: create symbolic in lumen laravel 
Php :: remove empty array elements php 
Php :: php interface vs abstract class 
Php :: search query in laravel 
Php :: laravel pluck relationship 
Php :: json to php array 
Php :: add array to array php 
Php :: Update Query in Codeigniter Using Multiple Where Condition 
Php :: check if array contains only unique values php 
Php :: php set status code 
Php :: laravel 8 decimal 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =