|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #77532 foreach iteration over keys without values
Submitted: 2019-01-28 00:24 UTC Modified: 2019-01-28 16:24 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: jerry at jmweb dot net Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2019-01-28 00:24 UTC] jerry at jmweb dot net
Too often I do something like:

foreach( $array as $key => $noop )
  // do something with $key only

Why not use array_keys? Well, I guess to avoid the overhead of calling a function. It would be super if we could simply do:

foreach( $array as $key => null )
  // do something with $key only

I am not 100% set on using null, but I will let the community decide on the specifics.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-01-28 00:38 UTC]
> but I will let the community decide on the specifics.

How about using '$noop' ?

In which case, the feature is complete.
 [2019-01-28 00:53 UTC] jerry at jmweb dot net
LOL. Obviously using the variable $noop works but I was hoping that the feature would 1) allow looping through keys w/out needing a variable for unused values and 2) possibly a speed bump over using array_keys.
 [2019-01-28 01:08 UTC]
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2019-01-28 11:40 UTC]
-Summary: foreach just over keys +Summary: foreach iteration over keys without values -Operating System: n/a +Operating System:
 [2019-01-28 11:40 UTC]
There was an RFC [1] started 3 years ago which hasn't seen any activity so maybe we should look back into it?

 [2019-01-28 16:24 UTC] jerry at jmweb dot net
What A fantastic RFC especially with no BC breaks! How can we get the RFC active again? I do not have experience with RFCs nor with C code so I can't verify if the patches are still compatible with the current codebase.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Sep 26 03:01:25 2023 UTC