Analyze the usage of the PHP function array_pop. We have introduced how to add elements at the beginning and end of an array. Next we will introduce how to delete array elements at the end of an array. First, we have introduced how to add elements at the beginning and end of an array. Next we will introduce how to delete array elements at the end of an array. First, we need to use the PHP function array_pop ().
- The array_pop () function deletes some elements from the end of the array:
- <?
-
- /* First, create an array */
-
- $FruitArray=Array("Apple", "orange", "banana", "Peach", "pear ");
-
- /* Use the array_pop () function to delete an element from the end of the array */
-
- $Popped=Array_pop($ 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 $ popped variable. its value is $ popped ";
-
- ?>
The result is as follows:
0: apple
1: orange
2: banana
3: Peach
Finally, the value of the element deleted by the PHP function array_pop () is stored in the $ popped variable, whose value is pear.
Bytes. Next we will introduce how to delete array elements at the end of an array. First, we...