PHP | ArrayIterator valid() Function Last Updated : 21 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The ArrayIterator::valid() function is an inbuilt function in PHP which is used to check whether an array contains more entries or not. Syntax: bool ArrayIterator::valid( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE if the iterator is valid, FALSE otherwise. Below programs illustrate the ArrayIterator::valid() function in PHP: Program 1: php <?php // Declare an ArrayIterator $arrItr = new ArrayIterator( array('G', 'e', 'e', 'k', 's') ); while ($arrItr->valid()) { echo "ArrayIterator Key: " . $arrItr->key() . " ArrayIterator Value: " . $arrItr->current() . "\n"; $arrItr->next(); } ?> Output: ArrayIterator Key: 0 ArrayIterator Value: G ArrayIterator Key: 1 ArrayIterator Value: e ArrayIterator Key: 2 ArrayIterator Value: e ArrayIterator Key: 3 ArrayIterator Value: k ArrayIterator Key: 4 ArrayIterator Value: s Program 2: php <?php // Declare an ArrayIterator $arrItr = new ArrayIterator( array( "a" => "Geeks", "b" => "for", "c" => "Geeks" ) ); // Using rewind function $arrItr->rewind(); while($arrItr->valid()) { var_dump($arrItr->current()); // Moving to next element $arrItr->next(); } ?> Output: string(5) "Geeks" string(3) "for" string(5) "Geeks" Reference: https://www.php.net/manual/en/arrayiterator.valid.php Comment More infoAdvertise with us Next Article PHP | ArrayIterator valid() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Iterators PHP-ArrayIterator +1 More Similar Reads PHP | ArrayIterator rewind() Function The ArrayIterator::rewind() function is an inbuilt function in PHP which is used to rewind the array back to the start. Syntax: void ArrayIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrat 1 min read PHP | ArrayIterator serialize() Function The ArrayIterator::serialize() function is an inbuilt function in PHP which is used to serialize the array iterator. Syntax: string ArrayIterator::serialize( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the serialized ArrayIterator. Below progr 1 min read PHP | DirectoryIterator valid() Function The DirectoryIterator::valid() function is an inbuilt function in PHP which is used to check the current DirectoryIterator position is a valid file or not. Syntax: bool DirectoryIterator::valid( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE 1 min read PHP | AppendIterator valid() Function The AppendIterator::valid() function is an inbuilt function in PHP which is used to check the validity of the current element. Syntax: bool AppendIterator::valid( void ) Parameters: This function does not accept any parameters. Return Value: This function returns TRUE if the current iteration is val 1 min read PHP | ArrayIterator seek() Function The ArrayIterator::seek() function is an inbuilt function in PHP which is used to seek the position of an array iterator. Syntax: void ArrayIterator::seek( int $position ) Parameters: This function accepts single parameter $position which holds the position to seek. Return Value: This function does 1 min read PHP | ArrayIterator seek() Function The ArrayIterator::seek() function is an inbuilt function in PHP which is used to seek the position of an array iterator. Syntax: void ArrayIterator::seek( int $position ) Parameters: This function accepts single parameter $position which holds the position to seek. Return Value: This function does 1 min read PHP | ArrayIterator unserialize() Function The ArrayIterator::unserialize() function is an inbuilt function in PHP which is used to unserialize the serialize object. Syntax: void ArrayIterator::unserialize( string $serialized ) Parameters: This function accepts single parameter $serialized which holds the serialize array iterator object. Ret 2 min read PHP | ArrayIterator uasort() Function The ArrayIterator::uasort() function is an inbuilt function in PHP which is used to sort the element using a user-defined comparison function and maintain their index association. Syntax: void ArrayIterator::uasort( callable $cmp_function ) Parameters: This function accepts a single parameter $cmp_f 2 min read PHP | ArrayIterator key() Function The ArrayIterator::key() function is an inbuilt function in PHP which returns the current key of the array element. Syntax: mixed ArrayIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the current array key. Below programs illustrate 1 min read PHP | ArrayIterator next() Function The ArrayIterator::next() function is an inbuilt function in PHP which is used to move the iterator to the next entry. Syntax: void ArrayIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustrate t 1 min read Like