Let's give an example:
Copy CodeThe code is as follows:
$arr = Array (' A ', ' B ', ' C ', ' d ');
Unset ($arr [1]);
Print_r ($arr);
?>
I had imagined that after unset, the array $arr should compress the array to fill the missing element position, but after Print_r ($arr), the result was not that, and the end result was an array ([0] = a [2] = c [3] + D);
If that's the case, let's take a look at the form of a digital array
Copy the Code code as follows:
$arr = range (5,10,4);
Print_r ($arr);//Array ([0] = 5 [1] = 6 [2] = 7 [3] = 8 [4] = 9 [5] [+] =)
Unset ($arr [1]);//Array ([0] = 5 [2] = 7 [3] = 8 [4] = 9 [5] + =)
Print_r ($arr);
?>
You can see that the form of the output is also the position where the array is to fill the missing element. So how can the missing elements be filled and the array will be re-indexed? The answer is Array_splice ():
Copy the Code code as follows:
$arr = Array (' A ', ' B ', ' C ', ' d ');
Array_splice ($arr, 1, 1);
Array ([0] = a [1] = c [2] = + D)
?>