WP_CLI\Utils

assoc_args_to_str()WP-CLI 1.0

Composes associative arguments into a command string.

Хуков нет.

Возвращает

Строку.

Использование

assoc_args_to_str( $assoc_args );
$assoc_args(массив) (обязательный)
Associative arguments to compose.

Код assoc_args_to_str() WP-CLI 2.8.0-alpha

function assoc_args_to_str( $assoc_args ) {
	$str = '';

	foreach ( $assoc_args as $key => $value ) {
		if ( true === $value ) {
			$str .= " --$key";
		} elseif ( is_array( $value ) ) {
			foreach ( $value as $v ) {
				$str .= assoc_args_to_str(
					[
						$key => $v,
					]
				);
			}
		} else {
			$str .= " --$key=" . escapeshellarg( $value );
		}
	}

	return $str;
}