|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-12-08 13:44 UTC] math dot piot at gmail dot com
Description:
------------
If I do a array_value on an empty array, it doesn't work. It works well if there is as least 1 value in the array.
Test script:
---------------
$array[] = 'data1'; // I want [0 => 'data1']
unset($array[0]); // I want []
$array = array_values($array); // I want [] but keys resetted
$array[] = 'data2'; // I want [0 => 'data2']
$array[] = 'data3'; // I want [0 => 'data2', 1 => 'data3']
var_dump($array);
Expected result:
----------------
array(2) {
[0]=>
string(5) "data2"
[1]=>
string(5) "data3"
}
Actual result:
--------------
array(2) {
[1]=>
string(5) "data2"
[2]=>
string(5) "data3"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
looks like a terrible BC break in 7.2 and i can remember recently that we wrote code to get the first remaining value after cleanup by $first = array_values($array)[0] which would no longer work with PHP 7.2 preserve keys here makes no sense 7.1.12: array(2) { [0]=> string(5) "data2" [1]=> string(5) "data3" } 7.2.1-dev: array(2) { [1]=> string(5) "data2" [2]=> string(5) "data3" }