Getting started with php array: deleting element values from the array header

Source: Internet
Author: User
Tags getting started with php
Getting started with php array: deleting element values from the array header
This article introduces how to delete element values from the php array header. For more information, see.

This section describes how to delete a value from the php array header,

You can use the php array function array_shift () to delete the function and return the elements found in the array.

The result is that if a numeric value is used, all corresponding values are moved down, and the array using the correlated key is not affected.

The format is mixed array_shift (array)

Example: delete the first element in the $ fruits array, apple:

     

This article introduces how to delete values from the array header. here we will add a method to delete elements from the array for your reference.

Delete elements from the php array

If you want to delete an element from an array, you can use the unset directly. For example:

     

But something strange happened. after print_r ($ arr), the result is not that, the final result is Array ([0] => a [2] => c [3] => d)

How can we fill in the missing elements and re-index the array? In this case, the array_splice () function is required:

     

In this way, after print_r ($ arr), the result is Array ([0] => a [1] => c [2] => d ).

Let's take a look at this and hope to help you understand how to delete the specified element value in the php array.

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: info-contact@alibabacloud.com 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.