PHP two methods for getting the last value of the array, array two _ PHP Tutorial

Source: Internet
Author: User
PHP can obtain the last value of an array in two ways: Array. PHP can obtain the last value of an array in two ways. the code for copying an array is as follows: $ arrayarray (, 5); echo $ array [count ($ array) -1]; calculate the length of the array, and then obtain the PHP of the array to obtain the last value of the array. There are two methods: Array 2.

The code is as follows:


$ Array = array (1, 2, 3, 4, 5 );
Echo $ array [count ($ array)-1]; // calculates the length of the array and obtains the last element of the array. if the last element in the array contains a non-numeric key name, the result may not match the expectation.
// Applies to an array with the key name and number
Echo'
';
Echo end ($ array); // point the internal pointer of the array to the last unit, applicable to all arrays

The explain code is as follows: $ array = array (, 5); echo $ array [count ($ array)-1]; // calculates the array length, then retrieve the array's most...

Related Article

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.