1 options.module options_array_transpose($array)

Manipulates 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.:

File

core/modules/field/modules/options/options.module, line 362
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function options_array_transpose($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;
}