|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-04-23 06:53 UTC] raat1979 at gmail dot com
[2016-04-23 07:37 UTC] raat1979 at gmail dot com
[2017-09-10 21:23 UTC] cmb@php.net
-Status: Open
+Status: Feedback
-Package: SPL related
+Package: Arrays related
-Assigned To:
+Assigned To: cmb
[2017-09-10 21:23 UTC] cmb@php.net
[2017-09-10 21:40 UTC] raat1979 at gmail dot com
-Status: Feedback
+Status: Assigned
[2017-09-10 21:40 UTC] raat1979 at gmail dot com
[2017-09-10 21:44 UTC] raat1979 at gmail dot com
[2017-09-11 12:17 UTC] cmb@php.net
-Status: Assigned
+Status: Open
-Assigned To: cmb
+Assigned To:
[2017-09-11 12:17 UTC] cmb@php.net
[2021-11-15 16:38 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2021-11-15 16:38 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 11:00:01 2025 UTC |
Description: ------------ array_push returns count(array) as a return value For arrays containing associative key this is quite useless it would have been better if it returned the key of the last item it added Test script: --------------- //php implementation function array_add(array &$array,$value /*[, $...]*/){ $values = func_get_args(); //get all values $values[0]= &$array; //BY REFERENCE! $org=key($array); //where are we? call_user_func_array('array_push',$values); end($array); // move to the last item $key = key($array); //get the key of the last item if($org===null){ //was at eof, added something, moved to it,fine return $key; }elseif($org<(count($array)/2)){ //somewhere in the middle +/- is fine reset($array); while (key($array) !== $org) next($List); }else{ while (key($array) !== $org) prev($List); } return $key; } Expected result: ---------------- $pr = array( [foo] => bar [bar] => foo ); array_push($pr,1) //returns 3 array_push($pr,1,2) //returns 4 array_add($pr,1) //returns 0 array_add($pr,1,2) //returns 1