note 64530 deleted from control-structures.foreach by bjori

From: Date: Tue, 18 Apr 2006 07:50:21 +0000
Subject: note 64530 deleted from control-structures.foreach by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108384@lists.php.net to get a copy of this message
Note Submitter: egingell at sisna dot com Reason: bad code ---- For those of us without PHP5, you can still use references for key and value. I haven't figured out how to get the key by referrence. I tried $key = &key($ary), but that didn't work. I recieved no error message either. <?php reset($ary); while (each($ary)) { $key = key($ary); $val = &$ary[($key ? $key : 0)]; // Seems that key() doesn't return int 0, hence the ternary opp. $val = $val . ' stuff'; // Do stuff to $val } ?>

« previous php.notes (#108384) next »