Req #72083 [Opn->Csd]: native array_add function; get last added key instead of count(array) with push

From: Date: Mon, 15 Nov 2021 16:38:39 +0000
Subject: Req #72083 [Opn->Csd]: native array_add function; get last added key instead of count(array) with push
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237772@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72083&edit=1 ID: 72083 Updated by: cmb@php.net Reported by: raat1979 at gmail dot com Summary: native array_add function; get last added key instead of count(array) with push -Status: Open +Status: Closed Type: Feature/Change Request Package: Arrays related Operating System: Irrelevant PHP Version: Next Minor Version -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Well, as of PHP 7.3.0 there is array_key_last()[1] which allows to retrieve the last array key. That should solve this issue, or do you disagree? [1] <https://www.php.net/manual/en/function.array-key-last.php> Previous Comments: ------------------------------------------------------------------------ [2017-09-11 12:17:25] cmb@php.net > Basically we need a php implementation of > zend_hash_next_free_element Thanks for the clarification. A pull request would be welcome. ------------------------------------------------------------------------ [2017-09-10 21:44:14] raat1979 at gmail dot com Basically we need a php implementation of zend_hash_next_free_element ------------------------------------------------------------------------ [2017-09-10 21:40:49] raat1979 at gmail dot com Sure, but after this I'd like to know the index of the item added. (which would contain a mix of numeric and assoc keys) ------------------------------------------------------------------------ [2017-09-10 21:23:28] cmb@php.net Sorry, I fail to understand what you are proposing. If I want to add an element to an arbitrary array, I would use $pr[] = $element; Wouldn't that work for you? ------------------------------------------------------------------------ [2016-04-23 07:37:23] raat1979 at gmail dot com Thinking about this there is currently is no (normal) way to get the next available numeric member of an array, one could consider this a bug ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=72083 -- Edit this bug report at https://bugs.php.net/bug.php?id=72083&edit=1

« previous php.bugs (#237772) next »