note 72841 added to function.array-uintersect

From: Date: Fri, 02 Feb 2007 20:03:32 +0000
Subject: note 72841 added to function.array-uintersect
Groups: php.notes 
Request: Send a blank email to php-notes+get-122575@lists.php.net to get a copy of this message
I want to stress that in the user function, you do need to return either a 1 or a -1 properly; you cannot simply return 0 if the results are equal and 1 if they are not. The following code is incorrect: <?php function myfunction($v1,$v2) { if ($v1===$v2) { return 0; } return 1; } $a1=array(1, 2, 4); $a2=array(1, 3, 4); print_r(array_uintersect($a1,$a2,"myfunction")); ?> This code is correct: <?php function myfunction($v1,$v2) { if ($v1===$v2) { return 0; } if ($v1 > $v2) return 1; return -1; } $a1=array(1, 2, 4); $a2=array(1, 3, 4); print_r(array_uintersect($a1,$a2,"myfunction")); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 68.255.110.228 ---- Manual Page -- http://www.php.net/manual/en/function.array-uintersect.php Edit -- https://master.php.net/note/edit/72841 Del: integrated -- https://master.php.net/note/delete/72841/integrated Del: useless -- https://master.php.net/note/delete/72841/useless Del: bad code -- https://master.php.net/note/delete/72841/bad+code Del: spam -- https://master.php.net/note/delete/72841/spam Del: non-english -- https://master.php.net/note/delete/72841/non-english Del: in docs -- https://master.php.net/note/delete/72841/in+docs Del: other reasons-- https://master.php.net/note/delete/72841 Reject -- https://master.php.net/note/reject/72841 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122575) next »