WP_CLI\Utils
iterator_map()
Like array_map(), except it returns a new iterator, instead of a modified array.
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); }
Хуков нет.
Возвращает
Объект
. An iterator that applies the given callback(s).
Использование
iterator_map( $it, $fn );
- $it(массив|объект) (обязательный)
- Either a plain array or another iterator.
- $fn(callback) (обязательный)
- The function to apply to an element.
Код iterator_map() iterator map WP-CLI 2.8.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; }