function _convert_csv_to_array

8.0.x drush.inc _convert_csv_to_array($args)
6.x drush.inc _convert_csv_to_array($args)
7.x drush.inc _convert_csv_to_array($args)
4.x drush.inc _convert_csv_to_array($args)
5.x drush.inc _convert_csv_to_array($args)
master drush.inc _convert_csv_to_array($args)

Convert a csv string, or an array of items which may contain csv strings, into an array of items.

@returns array A simple list of items (e.g. array('a','b','c')

Parameters

$args: A simple csv string; e.g. 'a,b,c' or a simple list of items; e.g. array('a','b','c') or some combination; e.g. array('a,b','c') or array('a,','b,','c,')

6 calls to _convert_csv_to_array()
drush_role_add_perm in commands/core/role.drush.inc
Add one or more permission(s) to the specified role.
drush_role_remove_perm in commands/core/role.drush.inc
Remove permission(s) from the specified role.
pm_parse_arguments in commands/pm/pm.drush.inc
Sanitize user provided arguments to several pm commands.
UserList::getFromOptions in lib/Drush/User/UserList.php
UserList::getFromParameters in lib/Drush/User/UserList.php
Given a comma-separated list of inputs, return accounts for users that match by uid,name or email address.

... See full list

File

includes/drush.inc, line 199
The drush API implementation and helpers.

Code

function _convert_csv_to_array($args) {
  //
  // Step 1: implode(',',$args) converts from, say, array('a,','b,','c,') to 'a,,b,,c,'
  // Step 2: explode(',', ...) converts to array('a','','b','','c','')
  // Step 3: array_filter(...) removes the empty items
  // Step 4: array_map(...) trims extra whitespace from each item
  // (handles csv strings with extra whitespace, e.g. 'a, b, c')
  //
  return array_map('trim', array_filter(explode(',', is_array($args) ? implode(',', $args) : $args)));
}