PHP-Get array kinsoku elements

Source: Internet
Author: User
Tags prev

Gets the first (first element) of the arrayReset

(PHP 4, PHP 5)

Reset - Point The inner pointer of the array to the first cell

Description

Reset   (   array   & $array   )

Reset () the array internal pointer is inverted back to the first cell and returns the value of the first array cell.

Parameters
    • array

    • The input array.

return value

Returns the value of the first cell of the array, or returns FALSE If the array is empty.

Example

Example #1 Reset () Example

<?php

$array= Array (' Step One ', ' Step ', ' Step three ', ' Step four ');

By default, the pointer are on the first element
Echo Current($array) . "<br/>\n"; "Step One"

Skip Steps
Next($array);
Next($array);
Echo Current($array) . "<br/>\n"; //"Step three"

Reset pointer, start again on step one
Reset($array);
Echo Current($array) . "<br/>\n"; //"Step One"

?>

See
    • Current ()-Returns the cell in the array

    • each ()-Returns the current key/value pair in the array and moves the array pointer one step forward

    • Prev ()-Returns the internal pointer of the array back to a

    • Reset ()-Points the inner pointer of the array to the first cell

    • Next ()-Moves the inner pointer in the array forward one


get Last (tail element)End

(PHP 4, PHP 5)

end-the inner pointer of an array to the last cell

Description

Mixed End ( array &$array )

End () array moves the internal pointer to the last cell and returns its value.

Parameters
    • array

    • This array. The array is passed by reference, because it is modified by this function. This means that you must pass in a real variable, not an array returned by the function, because only the real variable can be passed by reference.

return value

Returns the value of the last element, or if an empty array is returned FALSE .

Example

Example #1 End () example

<?php

$fruits= Array (' Apple ', ' Banana ', ' Cranberry ');
EchoEnd($fruits); Cranberry

?>

See
    • Current ()-Returns the cell in the array

    • each ()-Returns the current key/value pair in the array and moves the array pointer one step forward

    • Prev ()-Returns the internal pointer of the array back to a

    • Reset ()-Points the inner pointer of the array to the first cell

    • Next ()-Moves the inner pointer in the array forward one


This article from "I am a phper, simple and naïve" blog, please be sure to keep this source http://thinkforphp.blog.51cto.com/8733331/1784642

PHP-Get array kinsoku elements

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.