note 52947 added to function.array-intersect

From: Date: Wed, 18 May 2005 18:19:31 +0000
Subject: note 52947 added to function.array-intersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-89593@lists.php.net to get a copy of this message
$a = array(1,2,3,4,5,2,6,1); /* repeated elements --> $a is not a set */ $b = array(0,2,4,6,8,5,7,9,2,1); /* repeated elements --> $b is not a set */ $ua = array_merge(array_unique($a)); /* now, $a is a set */ $ub = array_merge(array_unique($b)); /* now, $b is a set */ $intersect = array_merge(array_intersect($ua,$ub)); Note: 'array_merge' removes blank spaces in the arrays. Note: order doesn't matter. In one line: $intersect_a_b = array_merge(array_intersect(array_merge(array_unique($a)), array_merge(array_unique($b)))); Additions/corrections wellcome... gRiNgO ---- Manual Page -- http://www.php.net/manual/en/function.array-intersect.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52947 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52947&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52947&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52947&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52947&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52947&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52947&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#89593) next »