PHP Array Operations

Source: Internet
Author: User
Method One:

 
  

Output

Output 8

Method Two:

 
  

Output

Output 8


Method Three:

 
  

Output

Array ([0] = 8)



The second method has the disadvantage that the Array_pop () function will "take out" the last number of the original data, that is, the meaning of the cut, the original data will no longer have the last value.

Such as:

 
  

Output:

Array ([0] = 1 [1] = 2 [2] = 4 [3] = 6)



These are the built-in functions in PHP, and we can actually get the last element in the PHP array by some of our own methods.

 
  

Of course, if the built-in method can be implemented, we try to use PHP's built-in functions, because in terms of efficiency or time, the built-in method is the most efficient, but in the process of development, if we do not know the existence of this method or do not remember this method, We can also write our own method of function according to our own logic.

  • 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.