function content_transpose_array_rows_cols in Content Construction Kit (CCK) 6.2
Same name and namespace in other branches
- 5 content.module \content_transpose_array_rows_cols()
- 6.3 content.module \content_transpose_array_rows_cols()
- 6 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.
2 calls to content_transpose_array_rows_cols()
- optionwidgets_data2form in modules/
optionwidgets/ optionwidgets.module - Helper function to transpose the values as stored in the database to the format the widget needs. Can be called anywhere this transformation is needed.
- optionwidgets_form2data in modules/
optionwidgets/ optionwidgets.module - Helper function to transpose the values returned by submitting the widget to the format to be stored in the field. Can be called anywhere this transformation is needed.
File
- ./
content.module, line 1629 - 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;
}