Doc #76971 [Opn->Ver]: Changed array append behaviour of array_unique

From: Date: Thu, 04 Oct 2018 17:47:48 +0000
Subject: Doc #76971 [Opn->Ver]: Changed array append behaviour of array_unique
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-16046@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76971&edit=1 ID: 76971 Updated by: cmb@php.net Reported by: bjoern dot fischer at dezem dot de Summary: Changed array append behaviour of array_unique -Status: Open +Status: Verified Type: Documentation Problem Package: Arrays related Operating System: Linux PHP Version: 7.2.10 Block user comment: N Private report: N New Comment: This behavioral change is caused by an optimization which only affects SORT_STRING mode[1]. Formerly the array has been copied and then non-unique elements have been deleted (without packing the array afterwards). Now a new array is built by adding the unique elements. Obiously, this can lead to different numeric indexes. [1] <http://git.php.net/?p=php-src.git;a=commit;h=6c2c7a023da4223e41fea0225c51a417fc8eb10d> Previous Comments: ------------------------------------------------------------------------ [2018-10-04 13:37:38] bjoern dot fischer at dezem dot de Description: ------------ --- From manual page: http://www.php.net/function.array-unique --- Beginning with PHP-7.2 appending an element to an array, after calling array_unique, changed behaviour. Before, the internal array-index-pointer was unchanged after calling array_unique, now with PHP 7.2 the array-index-pointer is set to the last remaining array element. This should be documented. This can be tested here: https://3v4l.org/IdmUX Test script: --------------- <?php $a = [0, 1, 2, 3, 3, 3]; $b = array_unique($a); $b[] = 4; var_dump($b); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76971&edit=1

« previous php.doc.bugs (#16046) next »