This article describes the method of removing element values from the header of a PHP array, with the need for a friend reference. This section describes how to delete values from the header of a PHP array. It can be implemented with the PHP array function array_shift (), which deletes and returns the elements found in the array. As a result, if you are using a numeric key, all corresponding values are moved down, and arrays that use the associated keys are not affected. The form is: Mixed Array_shift (array array) Example: Deleting the first element in a $fruits array Apple:
This paper introduces the method of removing the value from the array header, and here we add the method of removing the element in the array for reference. Delete element in PHP array If you want to delete an element in an array, you can use the unset directly. For example:
But the strange thing happened, after Print_r ($arr), the result is not that, the end result is Array ([0] = a [2] = c [3] + D) How can the missing elements be filled and the array will be re-indexed? The Array_splice () function is required to appear at this time:
Then, after Print_r ($arr), the result is an array ([0] = a [1] = = c [2] + D). Let's introduce these and hopefully help you master the method of removing the specified element value in the PHP array. |