note 104445 modified in function.array-udiff by danbrown

From: Date: Wed, 15 Jun 2011 18:12:14 +0000
Subject: note 104445 modified in function.array-udiff by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-180572@lists.php.net to get a copy of this message
Quick example for using array_udiff to do a multi-dimensional diff Returns values of $arr1 that are not in $arr2 <?php $arr1 = array( array('Bob', 42), array('Phil', 37), array('Frank', 39) ); $arr2 = array( array('Phil', 37), array('Mark', 45) ); $arr3 = array_udiff($arr1, $arr2, create_function( '$a,$b', 'return strcmp( implode("", $a), implode("", $b) ); ') ); print_r($arr3); ?> Output: Array ( [0] => Array ( [0] => Bob [1] => 42 ) [2] => Array ( [0] => Frank [1] => 39 ) ) 1 Hope this helps someone --was-- Quick example for using array_udiff to do a multi-dimensional diff Returns values of $arr1 that are not in $arr2 $arr1 = array( array('Bob', 42), array('Phil', 37), array('Frank', 39) ); $arr2 = array( array('Phil', 37), array('Mark', 45) ); $arr3 = array_udiff($arr1, $arr2, create_function( '$a,$b', 'return strcmp( implode("", $a), implode("", $b) ); ') ); print_r($arr3); Output: Array ( [0] => Array ( [0] => Bob [1] => 42 ) [2] => Array ( [0] => Frank [1] => 39 ) ) 1 Hope this helps someone http://php.net/manual/en/function.array-udiff.php

« previous php.notes (#180572) next »