function options_array_transpose in Drupal 7
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.
2 calls to options_array_transpose()
- _options_form_to_storage in modules/
field/ modules/ options/ options.module - Transforms submitted form values into field storage format.
- _options_storage_to_form in modules/
field/ modules/ options/ options.module - Transforms stored field values into the format the widgets need.
File
- modules/
field/ modules/ options/ options.module, line 351 - 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;
}