WP_CLI\Utils

iterator_map()WP-CLI 1.0

Example:

$arr = array('Football', 'Socker');

$it = iterator_map($arr, 'strtolower', function($val) {
  return str_replace('foo', 'bar', $val);
});
foreach ( $it as $val ) {
  var_dump($val);
}

No Hooks.

Return

Object. An iterator that applies the given callback(s).

Usage

iterator_map( $it, $fn );
$it(array|object) (required)
Either a plain array or another iterator.
$fn(callback) (required)
The function to apply to an element.

Код iterator_map() WP-CLI 2.7.0-alpha

function iterator_map( $it, $fn ) {
	if ( is_array( $it ) ) {
		$it = new ArrayIterator( $it );
	}

	if ( ! method_exists( $it, 'add_transform' ) ) {
		$it = new Transform( $it );
	}

	foreach ( array_slice( func_get_args(), 1 ) as $fn ) {
		$it->add_transform( $fn );
	}

	return $it;
}