Req #77532 [Opn]: foreach iteration over keys without values

From: Date: Mon, 28 Jan 2019 11:40:39 +0000
Subject: Req #77532 [Opn]: foreach iteration over keys without values
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219247@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77532&edit=1

 ID:                 77532
 Updated by:         girgias@php.net
 Reported by:        jerry at jmweb dot net
-Summary:            foreach just over keys
+Summary:            foreach iteration over keys without values
 Status:             Open
 Type:               Feature/Change Request
 Package:            Scripting Engine problem
-Operating System:   n/a
+Operating System:   
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

There was an RFC [1] started 3 years ago which hasn't seen any activity so maybe we should look
back into it?

[1]: https://wiki.php.net/rfc/foreach_void


Previous Comments:
------------------------------------------------------------------------
[2019-01-28 00:53:27] 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 00:38:42] danack@php.net

> 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:24:43] jerry at jmweb dot net

Description:
------------
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.



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77532&edit=1


Thread (1 message)

  • girgias@php.net
  • Unknown Message
    • girgias@php.net
« previous php.bugs (#219247) next »