Exemplo
Output o valor da corrente e o próximo elemento na matriz:
<?php
$people = array("Peter", "Joe" , "Glenn" , "Cleveland");
echo current($people) . "<br>";
echo next($people);
?>
Exemplo executar » Definição e Uso
O next() função move o cursor interno para, e saídas, o elemento seguinte na matriz.
métodos relacionados:
- prev() - move o ponteiro interno para, e saídas, o elemento anterior na matriz
- current() - devolve o valor do elemento de corrente em um array
- end() - move o ponteiro interno para, e saídas, o último elemento na matriz
- reset() - move o ponteiro interno para o primeiro elemento da matriz
- each() - devolve a chave elemento corrente e o valor, e move o cursor para a frente interna
Sintaxe
next( array )
Parâmetro | Descrição |
---|---|
array | Requeridos. Especifica a matriz para usar |
Detalhes técnicos
Valor de retorno: | Retorna o valor do próximo elemento na matriz em sucesso, ou FALSE se não houver mais elementos |
---|---|
PHP Versão: | 4+ |
mais Exemplos
Exemplo 1
Uma demonstração de todos os métodos relacionados:
<?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
?>
Exemplo executar » <PHP matriz de referência