note 30881 modified in function.unset by stone

From: Date: Wed, 02 Jul 2003 20:20:40 +0000
Subject: note 30881 modified in function.unset by stone
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-51379@lists.php.net to get a copy of this message
How to delete from an array. Answer to [oseibert at haba-ag dot de]. Unset() completly deletes an entry from the array. If you want the array numeric keys follow in a natural order you can use array_values() also. function deleteKey($array, $keyname, $value) { end($array); $last = key($array); for($i=0; $i<=$last; $i++) { if($array[$i][$keyname] == $value) { unset($array[$i]); } } $newArray = array_values( $array ); return $newArray; } --was-- How to delete from an array. Answer to [oseibert at haba-ag dot de]. Unset() completly deletes an entry from the array. If you want the array numeric keys follow in a natural order you can use array_values() also. function deleteKey($array, $keyname, $value) { end($array); $last = key($array); for($i=0; $i<=$last; $i++) { if($array[$i][$keyname] = $value) { unset($array[$i]); } } $newArray = array_values( $array ); return $newArray; } http://www.php.net/manual/en/function.unset.php

« previous php.notes (#51379) next »