PHP array Getting Started tutorial remove element values from array header

Source: Internet
Author: User
Tags pear
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.