função de reset () do PHP
PHP completa matriz de referência
Exemplos
A saída dos elementos da matriz eo valor atual do próximo elemento, em seguida, redefinir o ponteiro interno para o primeiro elemento na matriz:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
$people = array("Peter", "Joe", "Glenn", "Cleveland");
echo current($people) . "<br>";
echo next($people) . "<br>";
echo reset($people);
?>
Correndo instância »
Definição e Uso
repor a função () no ponteiro interno para o primeiro elemento da matriz, e de saída.
métodos relacionados:
- Atual () - Retorna o valor do elemento atual na matriz.
- End () - o ponteiro interno para o último elemento na matriz, e de saída.
- Next () - o ponteiro interno para o próximo elemento na matriz, e de saída.
- PREV () - o ponteiro interno para o último elemento da matriz, e de saída.
- a each () - Retorna nomes e valores de chave do elemento atual, e o ponteiro interno avança.
gramática
reset( array )
参数 | 描述 |
---|---|
array | 必需。规定要使用的数组。 |
detalhes técnicos
retorna: | Se for bem sucedido, então o valor do primeiro elemento da matriz é retornado, se a matriz estiver vazia, retorna. |
---|---|
versão do PHP: | 4+ |
mais exemplos
exemplo 1
Todos os métodos de apresentação relevantes:
<?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
?>
Correndo instância »
PHP completa matriz de referência