note 81882 added to function.unset

From: Date: Mon, 17 Mar 2008 21:41:37 +0000
Subject: note 81882 added to function.unset
Groups: php.notes 
Request: Send a blank email to php-notes+get-137148@lists.php.net to get a copy of this message
Sometimes you need to assigne values to an array index in some loop (if, while, foreach etc.) but you wish to set starting index key to some number greater then zero (lets say 5). One idea how to do this is: <?php $values = array(5, 10, 15, 100); //array of values that we wish to add to our new array $myArray = array(4=>0); //sets starting key to be 4 and assigns some value (lets say 0) unset($myArray[4]); //delete this index key, but preserves further enumeration foreach($values as $value){ $myArray[] = $value; //asign values to our array } print_r($myArray); /* Output: Array ( [5] => 5 [6] => 10 [7] => 15 [8] => 100 ) */ ?> ---- Server IP: 69.147.83.197 Probable Submitter: 89.216.99.199 ---- Manual Page -- http://www.php.net/manual/en/function.unset.php Edit -- https://master.php.net/note/edit/81882 Del: integrated -- https://master.php.net/note/delete/81882/integrated Del: useless -- https://master.php.net/note/delete/81882/useless Del: bad code -- https://master.php.net/note/delete/81882/bad+code Del: spam -- https://master.php.net/note/delete/81882/spam Del: non-english -- https://master.php.net/note/delete/81882/non-english Del: in docs -- https://master.php.net/note/delete/81882/in+docs Del: other reasons-- https://master.php.net/note/delete/81882 Reject -- https://master.php.net/note/reject/81882 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137148) next »