function drush_select_output_fields

8.0.x output.inc drush_select_output_fields($input, $fields, $mapping = array(), $default_value = NULL)
6.x output.inc drush_select_output_fields($input, $fields, $mapping = array(), $default_value = NULL)
7.x output.inc drush_select_output_fields($input, $fields, $mapping = array(), $default_value = NULL)
master output.inc drush_select_output_fields($input, $fields, $mapping = array(), $default_value = NULL)

Select the fields from the input array that should be output.

Parameters

$input: An associative array of key:value pairs to be output

$fields: An associative array that maps FROM a field in $input TO the corresponding field name in $output.

$mapping: An associative array that maps FROM a field in $fields TO the actual field in $input to use in the preceeding translation described above.

Return value

The input array, re-ordered and re-keyed per $fields

Related topics

2 calls to drush_select_output_fields()
drush_outputformat_key_value::format in commands/core/outputformat/key_value.inc
drush_outputformat_list::format in commands/core/outputformat/list.inc

File

includes/output.inc, line 402

Code

function drush_select_output_fields($input, $fields, $mapping = array(), $default_value = NULL) {
  $result = array();
  if (empty($fields)) {
    $result = $input;
  }
  else {
    foreach ($fields as $key => $label) {
      $value = drush_lookup_field_by_path($input, $key, $mapping, $default_value);
      if (isset($value)) {
        $result[$label] = $value;
      }
    }
  }
  return $result;
}