note 31926 modified in function.array-diff-assoc by aidan

From: Date: Wed, 09 Jun 2004 10:18:25 +0000
Subject: note 31926 modified in function.array-diff-assoc by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-70573@lists.php.net to get a copy of this message
To unset elements in an array if you know the keys but not the values, you can do: <?php $a = array("foo", "bar", "baz", "quux"); $b = array(1, 3); // Elements to get rid of foreach($b as $e) unset($a[$e]); ?> Of course this makes most sense if $b has many elements or is dynamically generated. --was-- IHMO the documentation is not entirely clear so just to clarify: This function looks at BOTH the key and the value, so you can't use it to unset a list elements in an array if you know the keys but not the values. Instead, you can e.g. do: <?php $a = array("foo", "bar", "baz", "quux"); $b = array(1, 3); // Elements to get rid of foreach($b as $e) unset($a[$e]); ?> Of course this makes most sense if $b has many elements or is dynamically generated. http://www.php.net/manual/en/function.array-diff-assoc.php

« previous php.notes (#70573) next »