You are here

function patterns_array_to_rows in Patterns 7

Same name and namespace in other branches
  1. 7.2 theme/common.inc \patterns_array_to_rows()

Helper function to transform an array of items, into an array of of arrays of items, so that the returned value can be themed with theme_table.

Parameters

array $array An array of items:

mixed $empty (optional) A string that will be added in case: the array is empty. Defaults NULL

Return value

array $array The transformed array

1 call to patterns_array_to_rows()
patterns_info_directories in includes/forms/info.inc
Displays a summary of available Patterns directories

File

theme/common.inc, line 124
Theme functions.

Code

function patterns_array_to_rows($array, $empty = NULL) {
  if (empty($array)) {
    $array = array(
      0 => array(),
    );
    if (!is_null($empty)) {
      $array[0][] = $empty;
    }
    return $array;
  }
  foreach ($array as $key => $value) {
    if (empty($key) || is_numeric($key)) {
      $array[$key] = array(
        $key + 1,
        $value,
      );
    }
    else {
      $array[$key] = array(
        $key,
        $value,
      );
    }
  }
  return $array;
}