#10203 [Com]: foreach weakness

From: Date: Mon, 08 Dec 2003 11:04:45 +0000
Subject: #10203 [Com]: foreach weakness
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-51800@lists.php.net to get a copy of this message
ID: 10203 Comment by: black at scene-si dot org Reported By: jack at mobil dot cz Status: Analyzed Bug Type: Feature/Change Request Operating System: all PHP Version: 4.0.4pl1 New Comment: just bumping this up, i guess someone would have to do it ;) foreach ($array as $key=>list($val1,$val2)) { .. } foreach ($array as list($val1,$val2)) { .. } the list should never take key values, the list should be only allowed in the right hand element making the following throw out an error: foreach ($array as list($k1,$k2)=>list($val1,$val2)) { .. } since afaik keys of tables are only 1 dimensional (not arrays). Previous Comments: ------------------------------------------------------------------------ [2002-01-29 04:19:59] yohgaki@php.net It's in TODO already :) Someone might implement it, but I guess it's not anytime soon. ------------------------------------------------------------------------ [2002-01-29 03:34:06] jack at mobil dot cz you haven't read the previous posts, have you? I think it's a general problem with list() construct, that you cannot use it everywhere you can use an L-value (or however you guys call it in PHP) ------------------------------------------------------------------------ [2002-01-28 20:45:41] yohgaki@php.net foreach ($arr as $key => $val) ------------------------------------------------------------------------ [2001-04-11 11:17:31] jack at mobil dot cz sure, I know I could use this way but I don't find it nice at all. ------------------------------------------------------------------------ [2001-04-06 14:42:55] torben@php.net It's for someone else to decide whether to add this to the language, but until they do you can achieve the same effect with: $arr = array(array(1, 2), array(3, 4)); foreach ($arr as $narr) { list($a, $b) = array_values($narr); echo "$a, $b\n"; } BTW--it would have helped if you had explained what results you were after and not just the syntax you wanted. ;) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/10203 -- Edit this bug report at http://bugs.php.net/?id=10203&edit=1

« previous php.bugs (#51800) next »