php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #9441 New feature for foreach control structure
Submitted: 2001-02-25 09:02 UTC Modified: 2009-05-04 15:08 UTC
From: php at leon dot brooks dot fdns dot net Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 4.0.4pl1 OS: (all, using) Linux 2.2.18
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 + 32 = ?
Subscribe to this entry?

 
 [2001-02-25 09:02 UTC] php at leon dot brooks dot fdns dot net
Would find it convenient to do this:

$filehandle=fopen("file","r");
foreach ($filehandle as $line) {
    # process line (line ends stripped off)
}
fclose ($filehandle);

...and even this...

$filehandle=fopen("file","r");
foreach ($filehandle as $line[]) {
    # $line[0] = whole line sans ends
    # $line[1] = first word (exploded out gawk-like)
    # $line[2] = second word, etc
}
fclose ($filehandle);

...just a thought.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-02 09:21 UTC] parham_m_s at hotmail dot com
i recently converted from perl to php and this was the first thing i realized.  The foreach construct should be implemented into files because it's just eyepleasing (and easier) for some people.  The same idea should also be applied to opendir (or even dumping an entire directory tree into an array).
 [2009-05-04 15:08 UTC] pajoye@php.net
Use file()
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 28 14:05:47 2022 UTC