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

search for in the

CachingIterator> <ArrayIterator::unserialize
[edit] Last updated: Fri, 25 May 2012

view this page in

ArrayIterator::valid

(PHP 5 >= 5.0.0)

ArrayIterator::validVérifie si un tableau contient d'autres entrées

Description

public bool ArrayIterator::valid ( void )

Vérifie si un tableau contient d'autres entrées.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Aucune valeur n'est retournée.

Exemples

Exemple #1 Exemple avec ArrayIterator::valid()

<?php
$array 
= array('1' => 'one');

$arrayobject = new ArrayObject($array);
$iterator $arrayobject->getIterator();

var_dump($iterator->valid()); //bool(true)

$iterator->next(); // avance au prochain élément

//bool(false) car il n'y a qu'un seul élément dans le tableau
var_dump($iterator->valid());
?>



add a note add a note User Contributed Notes ArrayIterator::valid
kaigillmann at gmxpro dot net 11-Nov-2005 01:55
Sometimes you need to search through the array.
Here is my object-orientated Version:

<?php
class MyArrayIterator extends ArrayIterator
{
    public function
available($value)
    {
        if (
in_array($value, (array)$this))
            return
true;
        else
            return
false;
    }
   
    public function
search($value)
    {
        foreach((array)
$this as $Key => $values)
        {
            if (
$values == $value)
                return
$Key;
        }
        return
false;
    }
}
?>

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