note 81000 added to function.array-intersect
| From: | Malte at osu1 dot php dot net | Date: | Sun, 10 Feb 2008 18:34:26 +0000 |
| Subject: | note 81000 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136005@lists.php.net to get a copy of this message | ||
Extending the posting by Terry from 07-Feb-2006 04:42:
If you want to use this function with arrays which have sometimes the same value several times, it
won't be checked if they're existing in the second array as much as in the first.
So I delete the value in the second array, if it's found there:
<?php
$firstarray = array(1, 1, 2, 3, 4, 1);
$secondarray = array(4, 1, 6, 5, 4, 1);
//array_intersect($firstarray, $secondarray): 1, 1, 1, 4
foreach ($firstarray as $key=>$value){
if (!in_array($value,$secondarray)){
unset($firstarray[$key]);
}else{
unset($secondarray[array_search($value,$secondarray)]);
}
}
//$firstarray: 1, 1, 4
?>
----
Server IP: 217.13.201.10
Probable Submitter: 88.77.60.141
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/81000
Del: integrated -- https://master.php.net/note/delete/81000/integrated
Del: useless -- https://master.php.net/note/delete/81000/useless
Del: bad code -- https://master.php.net/note/delete/81000/bad+code
Del: spam -- https://master.php.net/note/delete/81000/spam
Del: non-english -- https://master.php.net/note/delete/81000/non-english
Del: in docs -- https://master.php.net/note/delete/81000/in+docs
Del: other reasons-- https://master.php.net/note/delete/81000
Reject -- https://master.php.net/note/reject/81000
Search -- https://master.php.net/manage/user-notes.php