RE: [PHP] Array

From: Date: Thu, 15 Feb 2001 21:18:26 +0000
Subject: RE: [PHP] Array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39980@lists.php.net to get a copy of this message
if you want to "securely" remove an element of an array .... $objects = array('first','second','third','fourth','fifth','sixth','seventteen'); function remove_element($array, $left_id, $right_id) // Remove Element // left_id is element position(counts from 1) // right_id array position (counts from 0) { $left = array_slice ($array, 0, $left_id); $right = array_slice ($array, $right_id); $array = array_merge ($left, $right); unset ($left); unset ($right); return $array; } // just give both information of the element you want to remove. // if youi want to remove the third element transmit the array // position (2) and the "real" position (3) to the function, // and the element is gone ... $objects = remove_element($objects, 2,3); found on this page of PHP.Net http://www.php.net/manual/en/function.array-slice.php -----Original Message----- From: David Tandberg-Johansen [mailto:david@datajo.no] Sent: Thursday, February 15, 2001 5:05 AM To: php-general@lists.php.net Subject: [PHP] Array How can I delete one record in a array? Example: $myarray = array ("a", "b", "c"); I want to delete/take away "b" so the array is: $myarray = array ("a", "c"); David -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#39980) next »