#23453 [Fbk->NoF]: confusing docs on list vs. each

From: Date: Thu, 24 Jul 2003 03:31:09 +0000
Subject: #23453 [Fbk->NoF]: confusing docs on list vs. each
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969355455@lists.php.net to get a copy of this message
ID: 23453 Updated by: sniper@php.net Reported By: gearond at cvc dot net -Status: Feedback +Status: No Feedback Bug Type: Documentation problem Operating System: internet site PHP Version: 4.3.2RC2 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2003-07-18 20:18:11] 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-05-02 13:09:54] 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>" ); > } > > ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=23453&edit=1

« previous php.doc (#969355455) next »