|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2005-11-02 14:21 UTC] phpdev at citromail dot hu
  [2005-11-02 18:58 UTC] iliaa@php.net
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 03:00:01 2025 UTC | 
Description: ------------ I call a function with a reference to an array and an object. I then add the object to the end of the array. When I then use end() and key() to get the key of the the object just added to the array key() always returns 0 rather than the actual key value. Reproduce code: --------------- function addToArray(&$array, $obj) { $array[] = $obj; print_r($array); end($array); print 'last key = '.key($array).'<hr/>'; } print '<pre>'; $array = array(); for ($a=0; $a<5; $a++) addToArray($array, array($a=>$a)); print '</pre>'; Expected result: ---------------- I expect it to print to the screen an array dump followed by the last key value in the array 5 times (seperated by <hr>). I add an object to the array each time, so the last key value displayed should go from 0 to 4. Actual result: -------------- the last key value is always 0 rather than the actual last key value.