You are here

function content_transpose_array_rows_cols in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 content.module \content_transpose_array_rows_cols()
  2. 6 content.module \content_transpose_array_rows_cols()
  3. 6.2 content.module \content_transpose_array_rows_cols()

Manipulate a 2D array to reverse rows and columns.

The default data storage for fields is delta first, column names second. This is sometimes inconvenient for field modules, so this function can be used to present the data in an alternate format.

Parameters

$array: The array to be transposed. It must be at least two-dimensional, and the subarrays must all have the same keys or behavior is undefined.

Return value

The transposed array.

4 calls to content_transpose_array_rows_cols()
hook_widget in ./field.php
Define the behavior of a widget.
nodereference_widget in ./nodereference.module
Implementation of hook_widget().
optionwidgets_widget in ./optionwidgets.module
Implementation of hook_widget().
userreference_widget in ./userreference.module
Implementation of hook_widget().

File

./content.module, line 951
Allows administrators to associate custom fields to content types.

Code

function content_transpose_array_rows_cols($array) {
  $result = array();
  if (is_array($array)) {
    foreach ($array as $key1 => $value1) {
      if (is_array($value1)) {
        foreach ($value1 as $key2 => $value2) {
          if (!isset($result[$key2])) {
            $result[$key2] = array();
          }
          $result[$key2][$key1] = $value2;
        }
      }
    }
  }
  return $result;
}