php - Does array_a contain all elements of array_b -


if $array_b

$array_b = array('red', 'green', 'blue');  

what's efficient way compare $array_a , boolean whether $array_a contains elements of above $array_b.

this output i'm trying to

//false, because it's missing red `$array_b` $array_a = array('green', 'blue');   //true, because contains 3 `$array_b` $array_a = array('red', 'green', 'blue');       //true, because contains 3 `$array_b` //even though there's orange , cyan $array_a = array('red', 'green', 'blue', 'orange', 'cyan');  

what's way without nasty nested loops hard keep track of?

if (count(array_intersect($array_a, $array_b)) == count($array_b)) {     ... } 

or function

function function_name($array_a, $array_b) {     return count(array_intersect($array_a, $array_b)) == count($array_b); } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -