How can the RecursiveIteratorIterator be applied in PHP to simplify the process of iterating through complex multi-dimensional arrays?

When dealing with complex multi-dimensional arrays in PHP, iterating through them can be a cumbersome task. The RecursiveIteratorIterator class in PHP can be used to simplify this process by flattening the nested structure of the array and allowing for easy traversal of its elements.

// Example of using RecursiveIteratorIterator to iterate through a complex multi-dimensional array

$array = [
    'fruit' => ['apple', 'banana', 'cherry'],
    'colors' => ['red', 'green', 'blue'],
    'numbers' => [1, 2, 3]
];

$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));

foreach ($iterator as $key => $value) {
    echo $key . ': ' . $value . "\n";
}