php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #43837 Unclear Example in Control Structures foreach
Submitted: 2008-01-14 10:52 UTC Modified: 2008-01-18 11:13 UTC
From: php at wallbash dot com Assigned: sammywg (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2008-01-14 10:52 UTC] php at wallbash dot com
Description:
------------
I think this was introduced with #15488.

It states 
"/* foreach example 2: value (with key printed for illustration) */" 

but the example doesn't really print that key.

Thanks

Reproduce code:
---------------
http://www.php.net/manual/en/control-structures.foreach.php

Expected result:
----------------
/* foreach example 2: value (with key printed for illustration) */

$a = array(1, 2, 3, 17);

foreach ($a as $i => $v) {
    echo "\$a[$i] => $v.\n";
}

Actual result:
--------------
/* foreach example 2: value (with key printed for illustration) */

$a = array(1, 2, 3, 17);

$i = 0; /* for illustrative purposes only */

foreach ($a as $v) {
    echo "\$a[$i] => $v.\n";
    $i++;
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-14 12:01 UTC] rquadling@php.net
Example 2 is only showing the value. The "key" here is manually controlled and only shown to make some sense in the output.

Example 3 is the example you would be looking at to see the key and value from the foreach().
 [2008-01-18 11:13 UTC] sammywg@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 20:00:02 2026 UTC