Misunderstanding array_values

I have a problem to correctly define array_values ​​when I do this:

$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'] dump($array); 

I have a result:

 array:2 [β–Ό 1 => "data2" 2 => "data3" ] 

But I want:

 array:2 [β–Ό 0 => "data2" 1 => "data3" ] 

Can someone explain this to me? Because I lost a little: - /

For example, if I have an array with 10 values, delete the third value and make array_values on, it works well.

But if I remove the last value from the array, then when I do array_value, the next value I add always has id 1, not 0.

+5
source share
1 answer

This behavior has already been reported as an error: https://bugs.php.net/bug.php?id=75433 and (apparently as a result of this post) also: https://bugs.php.net/bug.php ? id = 75653

0
source

Source: https://habr.com/ru/post/1273937/


All Articles