- $arr = Array (' A ', ' B ', ' C ', ' d ');
- Unset ($arr [1]);
- Print_r ($arr);
- ?>
Copy CodeResult: Array ([0] = a [2] = c [3] + D) How does the missing element be filled and the array will be re-indexed? The answer is Array_splice (): Example:
- $arr = Array (' A ', ' B ', ' C ', ' d ');
- Array_splice ($arr, 1, 1);
- Print_r ($arr);
- ?>
Copy CodeResult: Array ([0] = a [1] = c [2] + D) Delete the specific element in the array (bbs.it-home.org script Academy):
- $arr 2 = Array (1, 3, 5,7,8);
- foreach ($arr 2 as $key = $value)
- {
- if ($value = = = 3)
- unset ($arr 2[$key]);
- }
- Var_dump ($arr 2);
- ?>
Copy CodeTo delete an empty array:
- $array = (' a ' + = ' abc ', ' B ' + = ' bcd ', ' c ' = ' CDE ', ' d ' and ' Def ', ' e ' = ' = ') ';
- Array_filter ($array);
- echo "
"; - Print_r ($array);
- ?>
Copy CodeResult: Array ([a] = ABC + BCD [c] = CDE [d] = def) Summary: If the Array_splice () function is deleted, the index value of the array also changes. If the unset () function is removed, the index value of the array does not change. |