note 82297 added to function.array-diff

From: Date: Fri, 04 Apr 2008 16:05:53 +0000
Subject: note 82297 added to function.array-diff
Groups: php.notes 
Request: Send a blank email to php-notes+get-137929@lists.php.net to get a copy of this message
Here's a little wrapper for array_diff - I found myself needing to iterate through the edited array, and I didn't need to original keys for anything. <?php function arrayDiff($array1, $array2){ # This wrapper for array_diff rekeys the array returned $valid_array = array_diff($array1,$array2); # reinstantiate $array1 variable $array1 = array(); # loop through the validated array and move elements to $array1 # this is necessary because the array_diff function returns arrays that retain their original keys foreach ($valid_array as $valid){ $array1[] = $valid; } return $array1; } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 75.171.113.54 ---- Manual Page -- http://www.php.net/manual/en/function.array-diff.php Edit -- https://master.php.net/note/edit/82297 Del: integrated -- https://master.php.net/note/delete/82297/integrated Del: useless -- https://master.php.net/note/delete/82297/useless Del: bad code -- https://master.php.net/note/delete/82297/bad+code Del: spam -- https://master.php.net/note/delete/82297/spam Del: non-english -- https://master.php.net/note/delete/82297/non-english Del: in docs -- https://master.php.net/note/delete/82297/in+docs Del: other reasons-- https://master.php.net/note/delete/82297 Reject -- https://master.php.net/note/reject/82297 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137929) next »