php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #14513 Fetch multiple elements from an array
Submitted: 2001-12-14 06:39 UTC Modified: 2001-12-17 02:26 UTC
From: daniel at lorch dot cc Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.1.0 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: daniel at lorch dot cc
New email:
PHP Version: OS:

 

 [2001-12-14 06:39 UTC] daniel at lorch dot cc
I was thinking about a new feature. Fetching multiple elements would be a cool feature, wouldn't it? This would look like this;

  $array[0,1];

or

  $array['name','address'];

and would allow constructions like this:

for($i=0;$i<count($array);$i+=2) {
  list($odd,$even)=$array[$i,$i+1];
}

instead of:

for($i=0;$i<count($array);$i+=2) {
  $odd=$array[$i];
  $even=$array[$i+1];
}

This syntactically follows the specification of using the "comma" to provide multiple elements/indices, such as it's already the case for functions. Therefore adding this feature wouldn't deteriorate the code-readability.

Also, I cannot think of any way using this feature to encourage bad coding practices.

$array from the above example could be a datafile from a guestbook where always a pair of lines represent "username" and "comment" (instead of using "|" or anything else as a delimitor).

Your comments?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-17 02:26 UTC] zak@php.net
Hey Daniel,

Check out the archived discussions in the zend engine 2 
mailing list regarding this topic. :)

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 10:01:29 2024 UTC