PHP Array operation--method to get the last value of the array, PHP array _php tutorial

Source: Internet
Author: User

PHP Array operation--method to get the last value of the array, PHP array


In the course of PHP development, it is often necessary to get the last health or value of an array for an array to be fetched. The home Help House summarizes three methods and describes the conditions under which they are used in some cases, according to their three methods.

<?php $array =array (1,2,3,4,5); Echo $array [Count ($array) -1];//computes the length of the array, and then gets 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 expected//applied to the array with the key named number Echo '
'; Echo End ($array);//The inner pointer of the array points to the last cell, for all arrays echo '
'; Rsort ($array);//reverse sequence of arrays, if the array contains letters or Chinese characters, the result may not meet the expected, the most suitable for the numeric array echo $array [0];?>

Overall, PHP's built-in function end is the best way to do it. We can test it.

PHP is easy to use, can be used loop traversal, class pointers (personally called), but if you go to the last value of the array is also used to traverse the words are not consumed a lot of performance ah??

There are three ways to take the last value of an array better:

This is the three function of the method of the value, directly valid, select it on Demand

March 31, 2012 Edit: The second method has a disadvantage, the Array_pop () function will be the last number of the original data "out", that is, the equivalent of cutting meaning, the original data will not have the last value

http://www.bkjia.com/PHPjc/983997.html www.bkjia.com true http://www.bkjia.com/PHPjc/983997.html techarticle PHP Array operation--the method to get the last value of the array, PHP array PHP development process, it may often be necessary to get the array to retrieve the last health or value of the array. Here to help the guests home ...

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