note 26514 deleted from function.array-diff by googleguy

From: Date: Tue, 22 Oct 2013 14:53:24 +0000
Subject: note 26514 deleted from function.array-diff by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197199@lists.php.net to get a copy of this message
Note Submitter: jg at sto dot com dot au ---- I have found an interesting use for array_diff. I remember seing somebody having trouble deleting from an array because it left "holes". I thought about using array_diff to fix the problem. Try running this code and see what it does: <?php for($i=0;$i<4;$i++) { print("Deleting item $i from the array<BR>"); $my_array = array("value1","value2","value3","value4"); $my_array = array_diff($my_array,array_slice($my_array,$i,1)); foreach($my_array as $value)print(" -->$value<BR>\n"); } ?> It seems to work for every member of the array. I'm not sure how efficient it would be on really large arrays, though. JG Estiot

« previous php.notes (#197199) next »