note 76391 deleted from function.array-diff by cmb

From: Date: Sun, 17 Mar 2019 09:38:41 +0000
Subject: note 76391 deleted from function.array-diff by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-210389@lists.php.net to get a copy of this message
Note Submitter: mr dot kschan at gmail dot com ---- 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.

« previous php.notes (#210389) next »