Analyze how PHP functions Array_pop () are used _php tutorials

Source: Internet
Author: User
Tags pear
We used to show you how to add elements to the tail of an array. Let's show you how to delete an array element at the end of an array. First, the function that we need to use is PHP function Array_pop ().

  • The function array_pop () removes some elements from the end of the array:

       
       
    1. ?
    2. /* First we create an array */
    3. $ Fruitarray = Array ("Apple", "orange", "banana", "Peach", "pear");
    4. /* Remove an element from the end of the array using the Array_pop () function */
    5. $ popped = Array_pop ($fruitArray);
    6. /* Now we'll show the key (key) and value of all the elements in the deleted array on the Web page */
    7. while (list ($key, $value) = each ($fruitArray)) {
    8. echo "$key: $value
      ";
    9. }
    10. echo "
      Finally, the value of the element that was just deleted is stored in the $popped variable, and its value is: $popped";
    11. ? >

    The results appear as follows:

    0:apple

    1:orange

    2:banana

    3:peach

    Finally, the value of the element deleted by the PHP function Array_pop () is stored in the $popped variable, and its value is: Pear.


    http://www.bkjia.com/PHPjc/446376.html www.bkjia.com true http://www.bkjia.com/PHPjc/446376.html techarticle we used to show you how to add elements to the tail of an array. Let's show you how to delete an array element at the end of an array. First of all, we ...

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.