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 code code is as follows:
!--? php $arr = Range (5,10,4);
Print_r ($arr);// array ([0] = 5 [1] = 6 [2] = 7 [3] =&G T 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 output is also in the form of an array where the missing elements are filled. So how can the missing elements be filled and the array will be re-indexed? The answer is Array_splice ():
!--? php
copy Code The code is as follows:
$arr = Array (' A ', ' B ', ' C ', ' d ');
Array_splice ($arr, 1, 1);
Print_r ($arr);//
array ([0] = a [1] = = c [2] = + D)
?
http://www.bkjia.com/phpjc/744325. HTML www.bkjia.com true http://www.bkjia.com/phpjc/744325.html techarticle Let's take an example: Copy the code as follows: PHP $arr = Array (' A ', ' B ', ' C ', ' d '); Unset ($arr [1]); Print_r ($arr);? I previously imagined that after unset, the array $arr should be compressed ...