Change language

PHP ArrayIterator valid () function

Syntax:
bool ArrayIterator::valid (void)
Parameters:This function takes no parameters.Return Value:This function returns TRUE if the iterator is valid, FALSE otherwise.The following programs illustrate the ArrayIterator::valid() function in PHP:
Program 1:  
// Declare ArrayIterator $arrItr = new ArrayIterator ( array ( ’G’ , ’e’ , ’ e’ , ’k’ , ’ s’ ) ); while ( $arrItr -> valid()) { echo "ArrayIterator Key:" . $arrItr -> key(). " ArrayIterator Value:" . $arrItr -> current(). "" ; $arrItr -> next(); }  
?>
Exit:
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:  
// Declare ArrayIterator $arrItr = new ArrayIterator ( array ( "a" = > "Geeks" , "b" = > "for" , "c" = > "Geeks" ));  
// Using the rewind function $arrItr -> rewind (); while ( $arrItr -> valid()) { var_dump ( $arrItr -> current()); // Move to next element $arrItr -> next(); }  
?>
Exit:
string (5 ) "Geeks" string (3) "for" string (5) "Geeks"
Link: https://www.php.net/manual/en/arrayiterator.valid.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method