Prąd PHP function ()
Przykłady
Prąd wyjściowy wartości elementu tablicy:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
?>
Uruchomienie instancji »
Definicja i Wykorzystanie
Aktualna funkcja () zwraca wartość bieżącego elementu w tablicy.
Każda tablica ma wewnętrzny wskaźnik do swojego "bieżącego" elementu, punktu początkowego wstawić do pierwszego elementu tablicy jest.
Wskazówka: Funkcja ta nie przesuwa wewnętrzny wskaźnik tablicy.
Podobne metody:
- End () - wewnętrzny wskaźnik do ostatniego elementu w tablicy i wyjście.
- Następny () - wewnętrzny wskaźnik do następnego elementu w tablicy, a wyjściem.
- PREV () - wewnętrzny wskaźnik do ostatniego elementu tablicy i wyjście.
- RESET () - wewnętrzny wskaźnik do pierwszego elementu tablicy, a wyjściem.
- each () - Zwraca nazwy klawiszy i wartości bieżącego elementu, a wewnętrzny wskaźnik porusza się do przodu.
gramatyka
current( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
dane techniczne
Zwraca: | Zwraca wartość bieżącego elementu tablicy, jeżeli bieżący element jest pusty lub wartość prądu element zwrócony FAŁSZ. |
---|---|
Wersja PHP: | 4+ |
Więcej przykładów
Przykład 1
Wszystkie odpowiednie metody prezentacji:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>"; // The current element is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
echo current($people) . "<br>"; // Now the current element is Joe
echo prev($people) . "<br>"; // The previous element of Joe is Peter
echo end($people) . "<br>"; // The last element is Cleveland
echo prev($people) . "<br>"; // The previous element of Cleveland is Glenn
echo current($people) . "<br>"; // Now the current element is Glenn
echo reset($people) . "<br>"; // Moves the internal pointer to the first element of the array, which is Peter
echo next($people) . "<br>"; // The next element of Peter is Joe
print_r (each($people)); // Returns the key and value of the current element (now Joe), and moves the internal pointer forward
?>
Uruchomienie instancji »
Kompletna PHP Array Reference