Example of deleting an element from a php array. Let's take an example: Copy the code as follows :? Php $ arrarray (a, B, c, d); unset ($ arr [1]); print_r ($ arr );? After unset, the array $ arr should be compressed. for example:
The code is as follows:
$ Arr = array ('A', 'B', 'C', 'D ');
Unset ($ arr [1]);
Print_r ($ arr );
?>
I previously imagined that after unset, the array $ arr should compress the array to fill in the missing element location, but after print_r ($ arr), the result is not that, the final result is Array ([0] => a [2] => c [3] => d );
If so, let's look at the form of a number array.
The code is as follows:
$ Arr = range (5, 10, 4 );
Print_r ($ arr ); // Array ([0] => 5 [1] => 6 [2] => 7 [3] => 8 [4] => 9 [5] => 10)
Unset ($ arr [1]); // Array ([0] => 5 [2] => 7 [3] => 8 [4] => 9 [5] => 10)
Print_r ($ arr );
?>
The output format is also the position where the array fills the missing element. So how can we fill in the missing elements and re-index the array? The answer is array_splice ():
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)
?>
The pipeline code is 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...