Introduction to using the PHP function array_shift () to delete array elements _ PHP Tutorial

Source: Internet
Author: User
Usage of the PHP function array_shift () in deleting array elements. In previous articles, we have described the specific usage of the array_pop () function for deleting array elements at the end of an array, today, we will introduce the specific usage of the array_pop () function for deleting array elements at the end of an array, today, we will introduce how to delete array elements at the beginning of an array. Here we will useNext we will show you how the PHP function array_shift () deletes elements from the beginning of the array:
 
 
  1. <?
  2. /* First, create an array */
  3. $FruitArray=Array("Apple", "orange", "banana", "Peach", "pear ");
  4. /* Use the array_shift () function to delete an element from the beginning of the array */
  5. $Shifted=Array_shift($ FruitArray );
  6. /* Now we display the keys and values of all elements in the deleted array on the webpage */
  7. While (list ($ key, $ value) = each ($ fruitArray )){
  8. Echo "$ key: $ value <br> ";
  9. }
  10. Echo "<br> Finally, the deleted element value is stored in the $ shifted variable. its value is:
  11. $ Shifted ";
  12. ?>

The result is as follows:

0: orange

1: banana

2: Peach

3: pear

Finally, the value of the element deleted by the PHP function array_shift () is stored in the $ shifted variable. its value is apple.


The specific usage of trim (), which we will introduce to you today is to delete the number at the beginning of the 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.