Home  >  Article  >  Backend Development  >  Definition and usage of php array function current()

Definition and usage of php array function current()

怪我咯
怪我咯Original
2017-06-06 11:43:342534browse

php current() definition?

The current() function in php returns the current element (unit) in the array. If the current element is empty or the current element has no value, it returns FALSE. Each array has an internal pointer pointing to its "current" element, which initially points to the first element inserted into the array. This function does not move the internal pointer of the array. If you need to move the pointer, you need to cooperate with other functions. Let’s take a look.

Related methods:

  • #end() - Point the internal pointer to the last element in the array and output

  • next() - Point the internal pointer to the next element in the array, and output

  • prev() - Point the internal pointer to the previous element in the array , and output

  • reset() - Point the internal pointer to the first element in the array, and output

  • each() - Return The key name and key value of the current element, and moves the internal pointer forward

Let’s take a look at its syntax

current(array)

The parameter array is the array that needs to be used

PS: The current() function returns the value of the array element currently pointed to by the internal pointer, and does not move the pointer. If the internal pointer points beyond the end of the cell list, current() returns FALSE.

Example

The following example demonstrates all related methods, the code is as follows

"; // 当前元素是 Bill
echo next($people) . "
"; // Bill 的下一个元素是 Steve echo current($people) . "
"; // 现在当前元素是 Steve echo prev($people) . "
"; // Steve 的上一个元素是 Bill echo end($people) . "
"; // 最后一个元素是 David echo prev($people) . "
"; // David 之前的元素是 Mark echo current($people) . "
"; // 目前的当前元素是 Mark echo reset($people) . "
"; // 把内部指针移动到数组的首个元素,即 Bill echo next($people) . "
"; // Bill 的下一个元素是 Steve print_r (each($people)); // 返回当前元素的键名和键值(目前是 Steve),并向前移动内部指针 ?>

The code running results are as follows:

Definition and usage of php array function current()

【Special Recommendation】

php array (Array)

【Related Article Recommendation】

Detailed explanation of the php end() function and current() function

php Detailed explanation of the usage examples of the current, next and reset function of the operating array function

The above is the detailed content of Definition and usage of php array function current(). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn