Example of current, next, and reset function usages in PHP

Source: Internet
Author: User
This article mainly introduces the use of current, next and reset functions in PHP, and describes in detail the specific usage of the current, next, and reset functions for array operations in PHP in the form of an instance. For an in-depth understanding of the use of arrays has some reference value, the need for friends can refer to the following

$array =array (' Step One ', ' Step ', ' step three ', ' step Four ');  Defines an array of echo current ($array). "
n "; Returns the first element of the array next ($array); The array pointer moves back one next ($array); The array pointer moves back one echo current ($array).
n "; Returns the current element of the array, the third value of Reset ($array); The pointer points to the first value of the array, echo current ($array).
n "; Returns the first value of the array// $info =array (' Red ', ' blue ', ' green '); Defines the array while ($result =current ($info)) { echo $result; echo "
"; Next ($info); } // $array =array (' fruit1 ' + ' apple ', ' fruit2 ' + ' orange ', ' fruit3 ' = ' grape ', ' fruit4 ' = ' Apple ', ' fruit5 ' = ' apple '); Define array while ($fruit _name=current ($array)) // loop Get array current value { if ($fruit _name== ' apple ')/ / If the current value is Apple { echo key ($array). '
'; Output the key name of the current value } next ($array); Move the array pointer down one step}

The end () function points the array's internal pointer to the last element and returns the value of the element, if successful.

The above describes the current, next and reset function usages in PHP, including the contents of the content, I hope that the PHP tutorial interested in a friend helpful.

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