PHP | AppendIterator key() Function Last Updated : 20 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The AppendIterator::key() function is an inbuilt function in PHP which is used to return the current key. Syntax: scalar AppendIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the current key if it is valid or NULL otherwise. Below programs illustrate the AppendIterator::key() function in PHP: Program 1: php <?php // Declare an ArrayIterator $arr1 = new ArrayIterator(array('G', 'e', 'e', 'k', 's')); // Create a new AppendIterator $itr = new AppendIterator; // Append the ArrayIterator element $itr->append($arr1); // Display the result while ($itr->valid()) { echo "ArrayIterator Key: " . $itr->key() . " ArrayIterator Value: " . $itr->current() . "\n"; $itr->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 $arr1 = new ArrayIterator( array( "a" => "Geeks", "b" => "for", "c" => "Geeks" ) ); $arr2 = new ArrayIterator( array( "x" => "Computer", "y" => "Science", "z" => "Portal" ) ); // Create a new AppendIterator $itr = new AppendIterator; $itr->append($arr1); $itr->append($arr2); $itr->rewind(); // Display the result while ($itr->valid()) { echo "ArrayIterator Key: " . $itr->key() . " ArrayIterator Value: " . $itr->current() . "\n"; $itr->next(); } ?> Output: ArrayIterator Key: a ArrayIterator Value: Geeks ArrayIterator Key: b ArrayIterator Value: for ArrayIterator Key: c ArrayIterator Value: Geeks ArrayIterator Key: x ArrayIterator Value: Computer ArrayIterator Key: y ArrayIterator Value: Science ArrayIterator Key: z ArrayIterator Value: Portal Reference: https://www.php.net/manual/en/appenditerator.key.php Comment More infoAdvertise with us Next Article PHP | AppendIterator key() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | AppendIterator next() Function The AppendIterator::next() function is an inbuilt function in PHP which is used to move the element into the next element. Syntax: void AppendIterator::next( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs illustr 2 min read PHP | CachingIterator key() Function The CachingIterator::key() function is an inbuilt function in PHP which is used to return the key for the current element. Syntax: scalar CachingIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the key value of the current element. B 1 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 append() Function The ArrayIterator::append() function is an inbuilt function in PHP which is used to append an element into an array iterator. Syntax: void ArrayIterator::append( mixed $value ) Parameters: This function accepts single parameter $value that holds the value that need to be append. Return Value: This f 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 | AppendIterator append() Function The AppendIterator::append() function is an inbuilt function in PHP which is used to append an iterator. Syntax: void AppendIterator::append( Iterator $iterator ) Parameters: This function accepts single parameter $iterator which holds the iterator to append. Return Value: This function does not ret 1 min read PHP | AppendIterator rewind() Function The AppendIterator::rewind() function is an inbuilt function in PHP which is used to rewind to the first element of the first inner Iterator. Syntax: void AppendIterator::rewind( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. B 1 min read PHP | AppendIterator current() Function The AppendIterator::current() function is an inbuilt function in PHP which is used to get the current value. Syntax: mixed AppendIterator::current( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the current value if it is valid or NULL otherwise. 1 min read PHP | DirectoryIterator key() Function The DirectoryIterator::key() function is an inbuilt function in PHP which is used to return the key for the current DirectoryIterator item. Syntax: string DirectoryIterator::key( void ) Parameters: This function does not accept any parameters. Return Value: This function returns the key for the curr 2 min read PHP | AppendIterator __construct() Function The AppendIterator::__construct() function is an inbuilt function in PHP which is used to construct an AppendIterator. Syntax: public AppendIterator::__construct( void ) Parameters: This function does not accept any parameters. Return Value: This function does not return any value. Below programs il 2 min read Like