PHP Delete Array Specify subscript element steps in detail

Source: Internet
Author: User
This time to bring you a PHP delete array in the specified subscript element steps, the PHP delete array in the specified subscript element of attention to what, the following is the actual case, take a look.

1, before the array as the stack and the queue to delete the element operation, that is, in order to delete the regular. So, what if you need to remove an element from the middle of the array? You need the unset () function We're going to talk about today.

2, the unset () function allows you to cancel an element in an array, but the array does not rebuild the index, that is, keep the original index, because the index in PHP has a special meaning.

3. Example shows:

<?php   $arr = Array (1=> ' one ',2=> ', ',3=> ' three ');       Delete the element labeled 2   unset ($arr [2]);//will get Array (1=> ' one ',3=> ' three ')    //Use Array_values () to re-index   $aar = Array_values ($arr); $aar = Array (0=> ' one ',1=> ' three ')?>

4, the last sentence in the above example code to re-establish the array index, here I explain the following: Because after using the unset () function to delete an element, and did not re-establish index subscript order. If you need a sequential index subscript, you can use the Array_values () function to recreate the index subscript order.

Note: The re-indexing of the premises refers to the re-establishment of an index starting at 0, even if your index is not numerically named, and is re-indexed.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

PHP replace article picture path to local server steps in detail

PHP's summary of source code encryption methods

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.