note 69881 deleted from control-structures.foreach by bjori

From: Date: Mon, 25 Sep 2006 08:02:03 +0000
Subject: note 69881 deleted from control-structures.foreach by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-117557@lists.php.net to get a copy of this message
Note Submitter: dave at jetcafe dot org Reason: so ---- 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?

« previous php.notes (#117557) next »