note 69881 added to control-structures.foreach

From: Date: Mon, 25 Sep 2006 02:07:13 +0000
Subject: note 69881 added to control-structures.foreach
Groups: php.notes 
Request: Send a blank email to php-notes+get-117546@lists.php.net to get a copy of this message
Note the following program <?php DEFINE("A",1); DEFINE("B",2); DEFINE("C",3); DEFINE("D",4); DEFINE("E",5); $a[E] = "Fifth"; $a[D] = "Fourth"; $a[A] = "First"; $a[B] = "Second"; $a[C] = "Third"; foreach ($a as $k => $v) { print "$k\n"; } ?> This prints: 5 4 1 2 3 So apparently order matters when you are adding values to an array. This certainly violates the principle of least surprise. Is there a reason for this? ---- Server IP: 64.71.164.2 Probable Submitter: 205.147.26.4 ---- Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php Edit -- https://master.php.net/note/edit/69881 Del: integrated -- https://master.php.net/note/delete/69881/integrated Del: useless -- https://master.php.net/note/delete/69881/useless Del: bad code -- https://master.php.net/note/delete/69881/bad+code Del: spam -- https://master.php.net/note/delete/69881/spam Del: non-english -- https://master.php.net/note/delete/69881/non-english Del: in docs -- https://master.php.net/note/delete/69881/in+docs Del: other reasons-- https://master.php.net/note/delete/69881 Reject -- https://master.php.net/note/reject/69881 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117546) next »