#23453 [NEW]: confusing docs on list vs. each

From: Date: Fri, 02 May 2003 18:09:54 +0000
Subject: #23453 [NEW]: confusing docs on list vs. each
Groups: php.doc 
Request: Send a blank email to phpdoc+get-969353036@lists.php.net to get a copy of this message
From: gearond at cvc dot net Operating system: internet site PHP version: 4.3.2RC2 PHP Bug Type: Documentation problem Bug description: confusing docs on list vs. each 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 bug report at http://bugs.php.net/?id=23453&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=23453&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=23453&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=23453&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=23453&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=23453&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=23453&r=support Expected behavior: http://bugs.php.net/fix.php?id=23453&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=23453&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=23453&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=23453&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23453&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=23453&r=dst IIS Stability: http://bugs.php.net/fix.php?id=23453&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=23453&r=gnused

« previous php.doc (#969353036) next »