note 27551 deleted from language.types.array by curt

From: Date: Tue, 06 Jul 2004 02:33:36 +0000
Subject: note 27551 deleted from language.types.array by curt
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72652@lists.php.net to get a copy of this message
Note Submitter: wjs@sympaticoDOTca ---- <?php /* Here is an array difficultly to watch for. The numeric indices into an array are NOT sequential, they are associative keys. */ // define an array with an offset of one $AnArray = array (1 => "Dog", "Cat", "Bat"); // add an element to the 0 index $AnArray[0] = "Rat"; // print this print_r($AnArray); // get this output /* Array ( [1] => Dog [2] => Cat [3] => Bat [0] => Rat ) */ /* The new value was added at the end, not the beginning as intended. Try using the push/pop/shift/unshift functions if order is important in the array. */ // This would have the proper effect from the example. // array_unshift($AnArray,"Rat"); /* The index will not unshift to less then 0 so additional unshift calls will begin to change the indices of the remaining elements. /* Or use the ksort() function to sort the keys. */ ?>

« previous php.notes (#72652) next »