iterator_to_array
Copy elements from the iterator to an array
Function name: iterator_to_array()
Function description: Convert an iterator to an array
Applicable version: PHP 5, PHP 7
Usage: iterator_to_array(Iterator $iterator, bool $use_keys = true)
parameter:
Return value: Returns the converted array.
Example:
$iterator = new ArrayIterator(['a' => 'apple', 'b' => 'banana', 'c' => 'cherry']); $array = iterator_to_array($iterator); print_r($array);
Output:
Array ( [a] => apple [b] => banana [c] => cherry )
$iterator = new ArrayIterator(['apple', 'banana', 'cherry']); $array = iterator_to_array($iterator, false); print_r($array);
Output:
Array ( [0] => apple [1] => banana [2] => cherry )
Notes: