php tutorial - PHP Delete Array Element - php programming - learn php - php code - php script
- Array is an important and mostly used data type in PHP programming.
- PHP programmer can add element to an array or delete element from an array manually with his/her own logical program but PHP also provides some built-in functions which help to delete array elements so easily.
Delete Array Last Element
- PHP array_pop() function is used to delete the last element of an array. The structure of the array_pop() function is given below
- The array_pop() function only accepts the name of an array and then it will remove the last element of that array.
- See below example where the array_pop() function is being used to remove the last element of an array
Sample Code
Output:
- The example shows that the last element of $web array is being removed by array_pop() function and the remaining elements are being shown using foreach loop statement.
Delete Array First Element
- PHP array_shift() function is used to remove the first element of an array. The structure of the array_shift() function is given below
- The array_shift() function only accepts the array name as an argument and then deletes the first element of that array.
- See below example where the array_shift() function is being used to remove the first element of an array
Sample Code
Output
- The example shows that the first element of $web array is being removed by the array_pop() function in every successful looping.