Req #44530 [Opn->Sus]: Multi-dimensional foreach iterator?

From: Date: Sat, 11 Apr 2020 13:43:01 +0000
Subject: Req #44530 [Opn->Sus]: Multi-dimensional foreach iterator?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226529@lists.php.net to get a copy of this message
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)

« previous php.bugs (#226529) next »