note 69712 added to function.in-array
| From: | nongjianz at yahoo dot com | Date: | Sun, 17 Sep 2006 01:08:18 +0000 |
| Subject: | note 69712 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117251@lists.php.net to get a copy of this message | ||
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;
}
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 68.67.55.50
----
Manual Page -- http://www.php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/69712
Del: integrated -- https://master.php.net/note/delete/69712/integrated
Del: useless -- https://master.php.net/note/delete/69712/useless
Del: bad code -- https://master.php.net/note/delete/69712/bad+code
Del: spam -- https://master.php.net/note/delete/69712/spam
Del: non-english -- https://master.php.net/note/delete/69712/non-english
Del: in docs -- https://master.php.net/note/delete/69712/in+docs
Del: other reasons-- https://master.php.net/note/delete/69712
Reject -- https://master.php.net/note/reject/69712
Search -- https://master.php.net/manage/user-notes.php