Usage of the PHP function array_shift () in deleting array elements. In previous articles, we have described the specific usage of the array_pop () function for deleting array elements at the end of an array, today, we will introduce the specific usage of the array_pop () function for deleting array elements at the end of an array, today, we will introduce how to delete array elements at the beginning of an array. Here we will useNext we will show you how the PHP function array_shift () deletes elements from the beginning of the array:
- <?
-
- /* First, create an array */
-
- $FruitArray=Array("Apple", "orange", "banana", "Peach", "pear ");
-
- /* Use the array_shift () function to delete an element from the beginning of the array */
-
- $Shifted=Array_shift($ FruitArray );
-
- /* Now we display the keys and values of all elements in the deleted array on the webpage */
-
- While (list ($ key, $ value) = each ($ fruitArray )){
-
- Echo "$ key: $ value <br> ";
-
- }
-
- Echo "<br> Finally, the deleted element value is stored in the $ shifted variable. its value is:
-
- $ Shifted ";
-
- ?>
The result is as follows:
0: orange
1: banana
2: Peach
3: pear
Finally, the value of the element deleted by the PHP function array_shift () is stored in the $ shifted variable. its value is apple.
The specific usage of trim (), which we will introduce to you today is to delete the number at the beginning of the array...