Php method for getting the first array unit value of an array _ PHP Tutorial

Source: Internet
Author: User
Tags array to string javascript array
Php is used to obtain the first array unit value. This article mainly describes how to obtain the value of the first array unit of an array in php. In php built-in functions, the functions used to obtain array element values mainly include reset. This article mainly describes how to obtain the value of the first array unit of an array in php. In php built-in functions, the functions used to obtain array element values mainly include the reset next current prev end functions.

Reset (PHP 3, PHP 4, PHP 5)

Function definition mixed reset (array & array)

Function: returns the internal pointer of array to the first unit and the value of the first array unit. If the array is null, FALSE is returned. For example:

 

Next (PHP 3, PHP 4, PHP 5)

Function definition mixed next (array & array)

Purpose: return the value of the next unit pointed to by the internal pointer of the array, or FALSE if no more units exist. For example:

  

Warning if the array contains an empty unit or the unit value is 0, FALSE is returned when this function encounters these units. To correctly traverse arrays that may contain null cells or whose unit value is 0, see the each () function.

Current (PHP 3, PHP 4, PHP 5)

Function definition mixed current (array & array)

Purpose: return the value of the array unit pointed to by the internal pointer, without moving the pointer. Initially point to the first unit inserted into the array. If the internal pointer points to an end that exceeds the cell List, current () returns FALSE.

Warning if the array contains an empty unit (0 or "", null string), this function returns FALSE when this unit is encountered. This makes it impossible to use current () to determine whether it has reached the end of the array list. To traverse arrays that may contain null cells correctly, use the each () function.

The behavior of next () and current () is similar. there is only one difference. before returning the value, move the internal pointer one byte forward. This means that it returns the value of the next array unit and moves the array pointer one bit forward. If the result of moving the pointer exceeds the end of the array unit, next () returns FALSE.

The following is an example of using related functions:

   Articles you may be interested in
   
   
  • Php uses array_flip to implement array key-value exchange to remove array duplicate values
  • JavaScript array explanation (how to declare and calculate arrays)
  • Summary of methods for removing duplicate values from a two-dimensional php array
  • How does php delete the first and last elements of an array?
  • Js array to string, js string to array method summary
  • Introduction to array union, intersection, and difference set functions in php
  • PHP generates continuous numbers (letters) array function range () analysis, PHP lottery program function
  • Php clears the null element in the array.

Bytes. In php built-in functions, the main functions used to obtain array element values include reset...

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.