|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44530 Multi-dimensional foreach iterator?
Submitted: 2008-03-25 14:22 UTC Modified: 2020-04-11 13:43 UTC
Avg. Score:4.0 ± 0.7
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: adrian at adecsys dot com Assigned:
Status: Suspended Package: Arrays related
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-03-25 14:22 UTC] adrian at adecsys dot com
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:


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.



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-09 01:10 UTC]
-Package: Feature/Change Request +Package: Arrays related -Operating System: WindowsXP +Operating System: * -PHP Version: 5.2.5 +PHP Version: *
 [2020-04-11 13:43 UTC]
-Status: Open +Status: Suspended
 [2020-04-11 13:43 UTC]
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] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 21 21:03:32 2021 UTC