note 76391 added to function.array-diff

From: Date: Fri, 13 Jul 2007 04:16:13 +0000
Subject: note 76391 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-128426@lists.php.net to get a copy of this message
just comment ... i don't know whether the following implementation of array_diff is having a much better meaning to the function name. function ary_diff( $ary_1, $ary_2 ) { // compare the value of 2 array // get differences that in ary_1 but not in ary_2 // get difference that in ary_2 but not in ary_1 // return the unique difference between value of 2 array $diff = array(); // get differences that in ary_1 but not in ary_2 foreach ( $ary_1 as $v1 ) { $flag = 0; foreach ( $ary_2 as $v2 ) { $flag |= ( $v1 == $v2 ); if ( $flag ) break; } if ( !$flag ) array_push( $diff, $v1 ); } // get difference that in ary_2 but not in ary_1 foreach ( $ary_2 as $v2 ) { $flag = 0; foreach ( $ary_1 as $v1 ) { $flag |= ( $v1 == $v2 ); if ( $flag ) break; } if ( !$flag && !in_array( $v2, $diff ) ) array_push( $diff, $v2 ); } return $diff; } i think array_diff should return the difference between the array independent of the order of passing the parameter. ---- Server IP: 203.169.164.81 Probable Submitter: 202.94.238.133 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/76391 Del: integrated -- https://master.php.net/note/delete/76391/integrated Del: useless -- https://master.php.net/note/delete/76391/useless Del: bad code -- https://master.php.net/note/delete/76391/bad+code Del: spam -- https://master.php.net/note/delete/76391/spam Del: non-english -- https://master.php.net/note/delete/76391/non-english Del: in docs -- https://master.php.net/note/delete/76391/in+docs Del: other reasons-- https://master.php.net/note/delete/76391 Reject -- https://master.php.net/note/reject/76391 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128426) next »