Let me give you an example:
Copy Code code as follows:
<?php
$arr = Array (' A ', ' B ', ' C ', ' d ');
Unset ($arr [1]);
Print_r ($arr);
?>
What I thought before was unset, the array $arr should compress the array to fill the missing element position, but after Print_r ($arr), the result is not that, and the end result is array ([0] => a [2] => C [3] => D);
If that's the case, let's take a look at the form of the array of numbers
Copy Code code as follows:
<?php
$arr = range (5,10,4);
Print_r ($arr);//<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:16PX; ">array ([0] => 5 [1] => 6 [2] => 7 [3] => 8 [4] => 9 [5] =>) </span>
Unset ($arr [1]);//<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:16PX; ">array ([0] => 5 [2] => 7 [3] => 8 [4] => 9 [5] =>) </span>
Print_r ($arr);
?>
You can see that the form of the output is also where the array fills the missing elements. So how do you get the missing elements to be filled and the array will be indexed again? The answer is Array_splice (): <pre name= "code" class= "PHP" ><?php
Copy Code code as follows:
$arr = Array (' A ', ' B ', ' C ', ' d ');
Array_splice ($arr, 1, 1);
Print_r ($arr); <span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:16PX; ">array ([0] => a [1] => C [2] => D) </span>
?>