note 9731 deleted from function.array-slice by jimw

From: Date: Mon, 10 Dec 2001 23:28:48 +0000
Subject: note 9731 deleted from function.array-slice by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-22458@lists.php.net to get a copy of this message
class array_tweak { function remove_element($array, $from, $to) // remove Element(S) from Array { // ($array, 4, 6) to remove elements 4 to 6 // ($array, 4, 4) just to remove a single element (4) $left = array_slice ($array, 0, $von-1); $right = array_slice ($array, $to); $array = array_merge ($left, $right); unset ($from); unset ($to); return $array; } function insert_element($array, $position, $elements_string) // add Element[S] { // ($array, 4, "newone") adds string "newone" to position 4 // (array, 0, "hot, cold, warm") adds hot to 1, cold to 2, warm to 3 if ($position == "0") $position = 1; $left = array_slice ($array, 0, $position-1); $right = array_slice ($array, $position-1); $insert = explode (",", $elements_string); $array = array_merge ($left, $insert, $right); unset ($left); unset ($right); return $array; } function move_element($array, $from, $to) // Move (single) Array Element { if ($from == 0) $from = 1; if ($to == 0) $to = 1; $hopper = $array[$from-1]; $array = $this->remove_element($array, $from, $from); $array = $this->insert_element($array, $to, $hopper); unset ($hopper); return $array; } }

« previous php.notes (#22458) next »