note 69712 deleted from function.in-array by felipe

From: Date: Sun, 30 Dec 2007 18:59:54 +0000
Subject: note 69712 deleted from function.in-array by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134491@lists.php.net to get a copy of this message
Note Submitter: nongjianz at yahoo dot com ---- in_array does not work for this case: If all items of an array as elements (not as an array) are in another array. For example: $arr1 = array("aaa", "bbb", "ccc", "ddd"); $arr2 = array("aaa", "bbb"); The following function is a solution to work it out: <? function arrElement_in_array($arr2, $arr1){ foreach($arr2 as $v){ if(in_array($v, $arr1)){ $count++; } } //if all elements of arr2 are in arr1 if($count==count($arr2)){ return true; } } ?>

« previous php.notes (#134491) next »