php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #23453 confusing docs on list vs. each
Submitted: 2003-05-02 13:09 UTC Modified: 2003-07-23 22:31 UTC
From: gearond at cvc dot net Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: 4.3.2RC2 OS: internet site
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gearond at cvc dot net
New email:
PHP Version: OS:

 

 [2003-05-02 13:09 UTC] gearond at cvc dot net
Dennis Gearon írta:

> The documentation of each() says:
>
>     array each ( array array)
>     --------------------------
>     Returns the current key and value pair from the array array and
>     advances the array cursor. This pair is returned in a
>     four-element array, with the keys 0, 1, key, and value.
>     Elements 0 and key contain the key name of the array element,
>     and 1 and value contain the data.
> The documentation of list() says:
>     Warning
>     --------
>
>     list() assigns the values starting with the right-most parameter.
>     If you are using plain variables, you don't have to worry about this.
>     But if you are using arrays with indices you usually expect the order
>     of the indices in the array the same you wrote in the list() from
>     left to right; which it isn't. It's assigned in the reverse order.
>
> =============================================================================
> To me, that says that each will issue an array with the element [0] containing the key of an array postion, and the element[1] containing the value of an
> array position.
> And so, using list on the array generated by each should assign the key to the
> rightmost variable in the list and the value to the next variable to the right.
> =============================================================================
>
>
> If you try this, it will print out opposite of what you expect. It prints out
> the keys to the array '$keys', not the values.
>
>                $event_fields_arr = array(
>                    "event_id" =>"",
>                    "usr_name" =>"",
>                    "usr_email" =>"",
>                    "centennial_name" =>"",
>                    "event_name" =>"",
>                    "event_category" =>"",
>                    "event_link" =>"",
>                    "event_cost" =>"",
>                    "event_phone" =>"",
>                    "event_begin_day" =>"",
>                    "event_begin_month" =>"",
>                    "event_begin_year" =>"",
>                    "event_end_day" =>"",
>                    "event_end_month" =>"",
>                    "event_end_year" =>"",
>                    "event_sched" =>"",
>                    "event_desc" =>"",
>                    "event_addr" =>"",
>                    "event_city" =>"",
>                    "event_state" =>"",
>                    "event_zip" =>"",
>                    "company_name" =>"",
>                    "company_addr" =>"",
>                    "company_city" =>"",
>                    "company_state" =>"",
>                    "company_zip" =>""
>                );
>                $keys = array_keys( $event_fields_arr );
>                while( list ($val, $key) = each( $keys ) ){
>                    echo( $val . "<br>" );
>                }
>
>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-18 20:18 UTC] philip@php.net
This is actually referring to a situation as shown in example #3 at php.net/list  You are not using an array, you are using plain variables, so don't need to worry about it...

Not sure how this can be rewritten, how do you think this can be solved?  All the examples demonstrate that your code in this report is wrong.
 [2003-07-23 22:31 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC