note 89485 added to function.array-intersect
| From: | OtoBrglez at osu1 dot php dot net | Date: | Tue, 10 Mar 2009 15:02:17 +0000 |
| Subject: | note 89485 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151692@lists.php.net to get a copy of this message | ||
If you wish to create intersection with arrays that are empty. Than the result of intersection is
empty array.
If you wish to change this. I sugest that you do this.
It simply "ignores" empty arrays. Before loop use 1st array.
<?php
$a = array();
$a[] = 1;
$a[] = 2;
$a[] = 3;
$b = array();
$b[] = 4;
$b[] = 5;
$b[] = 1;
$c = array();
$c[] = 1;
$c[] = 5;
$d = array();
$kb=array('a','b','c','d');
$out = $a;
foreach($kb as $k){
if(!empty(${$k})) $out = array_intersect($out,${$k});
};
print_r($out);
// The result is array
// The result is empty array
print_r(array_intersect($a,$b,$c,$d));
?>
----
Server IP: 213.250.2.28
Probable Submitter: 89.212.65.33
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/89485
Del: integrated -- https://master.php.net/note/delete/89485/integrated
Del: useless -- https://master.php.net/note/delete/89485/useless
Del: bad code -- https://master.php.net/note/delete/89485/bad+code
Del: spam -- https://master.php.net/note/delete/89485/spam
Del: non-english -- https://master.php.net/note/delete/89485/non-english
Del: in docs -- https://master.php.net/note/delete/89485/in+docs
Del: other reasons-- https://master.php.net/note/delete/89485
Reject -- https://master.php.net/note/reject/89485
Search -- https://master.php.net/manage/user-notes.php