Gli ultimi tutorial di sviluppo web
 

PHP reset() Function

<PHP Array Riferimento

Esempio

Uscita il valore dell'elemento corrente e successivo in una matrice, quindi reimpostare puntatore interno dell'array al primo elemento nella matrice:

<?php
$people = array("Peter", "Joe" , "Glenn" , "Cleveland");

echo current($people) . "<br>";
echo next($people) . "<br>";

echo reset($people);
?>
Esempio Run »

Definizione e l'utilizzo

Il reset() funzione sposta il puntatore interno al primo elemento della matrice.

Metodi correlati:

  • current() - restituisce il valore dell'elemento corrente in un array
  • end() - sposta il puntatore interno, e uscite, l'ultimo elemento dell'array
  • next() - sposta il puntatore interno, e uscite, il successivo elemento nella matrice
  • prev() - sposta il puntatore interno, e uscite, il precedente elemento dell'array
  • each() - restituisce la chiave e il valore dell'elemento corrente, e sposta il puntatore interno avanti

Sintassi

reset( array )

Parametro Descrizione
array Necessario. Specifica la matrice da usare

Dettagli tecnici

Valore di ritorno: Restituisce il valore del primo elemento dell'array ha successo, oppure FALSE se l'array è vuoto
Versione PHP: 4+

Altri esempi

esempio 1

Una dimostrazione di tutti i metodi correlati:

<?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
?>
Esempio Run »

<PHP Array Riferimento