Req #44530 [Opn->Sus]: Multi-dimensional foreach iterator?
Edit report at https://bugs.php.net/bug.php?id=44530&edit=1
ID: 44530
Updated by: cmb@php.net
Reported by: adrian at adecsys dot com
Summary: Multi-dimensional foreach iterator?
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Arrays related
Operating System: *
PHP Version: *
Block user comment: N
Private report: N
New Comment:
This feature deserves discussion beyond what is suitable for this
bug tracker. Therefore please bring that up on the internals
mailing list[1]; for the time being, I'm suspending this ticket.
[1] <https://www.php.net/mailing-lists.php#internals>
Previous Comments:
------------------------------------------------------------------------
[2008-03-25 14:22:51] adrian at adecsys dot com
Description:
------------
Suggestion is to support foreach() to iterate actoss multidimensional arrays.
Given a higher-order array, it would be very useful to be able to collapse nested foreach statements
into a single one. To exemplify:
given
$A[1][1]="A";
$A[1][2]="B";
$A[1][3]="C";
$A[2][1]="D";
etc.
foreach($A as $L1,$L2 => $V) {
// first iteration -- $L1=1, $L2=1, $V="A"
// second iteration -- $L1=1, $L2=2, $V="B"
// third iteration -- $L1=1, $L2=3, $V="C"
// fourth iteration -- $L1=2, $L2=1, $V="D"
}
I would have many uses for such a construct, and I'm hoping that I would not be alone.
KR
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=44530&edit=1
Thread (2 messages)