Permalink
Browse files

New helper_array_transpose api function

Required for issue #15774
  • Loading branch information...
1 parent 41cdb92 commit 3ee6137ccc93d5eee1cc2367bdd9d621424890e9 @dregad dregad committed with dregad Apr 23, 2013
Showing with 25 additions and 0 deletions.
  1. +25 −0 core/helper_api.php
View
@@ -66,6 +66,31 @@ function helper_alternate_class( $p_index = null, $p_odd_class = 'row-1', $p_eve
return "class=\"$p_even_class\"";
}
}
+/**
+ * Transpose a bidimensional array
+ *
+ * e.g. array('a'=>array('k1'=>1,'k2'=>2),'b'=>array('k1'=>3,'k2'=>4))
+ * becomes array('k1'=>array('a'=>1,'b'=>3),'k2'=>array('a'=>2,'b'=>4))
+ *
+ * @param array $p_array
+ * @return array|mixed transposed array or $p_array if not 2-dimensional array
+ */
+function helper_array_transpose( $p_array ) {
+ if( !is_array( $p_array ) ) {
+ return $p_array;
+ }
+ $t_out = array();
+ foreach( $p_array as $key => $sub ) {
+ if( !is_array( $sub ) ) {
+ return $p_array;
+ }
+
+ foreach( $sub as $subkey => $value ) {
+ $t_out[$subkey][$key] = $value;
+ }
+ }
+ return $t_out;
+}
/**
* get the color string for the given status, user and project

0 comments on commit 3ee6137

Please sign in to comment.