note 9728 deleted from function.array-slice by jimw

From: Date: Mon, 10 Dec 2001 23:28:37 +0000
Subject: note 9728 deleted from function.array-slice by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22457@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);

« previous php.notes (#22457) next »