downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

range> <pos
[edit] Last updated: Tue, 21 May 2013

view this page in

prev

(PHP 4, PHP 5)

prevDecrementa il puntatore interno dell'array

Descrizione

mixed prev ( array $array )

Restituisce l'elemento dell'array che sta nella posizione precedente a quella attuale indicata dal puntatore interno, oppure FALSE se non ci sono altri elementi.

Avviso

Se l'array contiene degli elementi vuoti la funzione restituirà FALSE per questi valori. Per esplorare correttamente un array che può contenere elementi vuoti vedere la funzione each().

prev() si comporta come next(), tranne per il fatto di decrementare il puntatore interno di una posizione, invece che incrementarlo.

Example #1 Esempio di prev() e funzioni relative

<?php
$trasporti 
= array('piedi''bicicletta''automobile''aereo');
$mode current($trasporti); // $mode = 'piedi';
$mode next($trasporti);    // $mode = 'bicicletta';
$mode next($trasporti);    // $mode = 'automobile';
$mode prev($trasporti);    // $mode = 'piedi';
$mode end($trasporti);     // $mode = 'aereo';
?>

Vedere anche current(), end(), next() e reset().



add a note add a note User Contributed Notes prev - [2 notes]
up
2
soapergem at gmail dot com
3 years ago
Here's a slight revision to xmlich02's backwards iteration example. The problem with his/her example is that it will halt if any of the array elements are boolean false, while this version will not.

<?php

end
($ar);
while ( !
is_null($key = key($ar)) ) {
   
$val = current($ar);
    echo
"{$key} => {$val}\n";
   
prev($ar);
}

?>
up
-1
xmlich02 at stud dot fit dot vutbr dot cz
5 years ago
// example of backward iteration

$ar = array ( 'a', 'b', 'c', 'd', 'e', 'f') ;

print_r($ar);

end($ar);
while($val = current($ar)) {
  echo $val.' ';
  prev($ar);
}

 
show source | credits | sitemap | contact | advertising | mirror sites