WP_CLI
Formatter::assoc_array_to_rows
Format an associative array as a table.
Method of the class: Formatter{}
No Hooks.
Returns
Array.
Usage
// private - for code of main (parent) class only $result = $this->assoc_array_to_rows( $fields );
- $fields(array) (required)
- Fields and values to format.
Formatter::assoc_array_to_rows() Formatter::assoc array to rows code WP-CLI 2.13.0-alpha
private function assoc_array_to_rows( $fields ) {
$rows = [];
foreach ( $fields as $field => $value ) {
if ( ! is_string( $value ) ) {
$value = json_encode( $value );
}
$rows[] = (object) [
'Field' => $field,
'Value' => $value,
];
}
return $rows;
}