From fdeb756e15f730a3dfd2a6f52a4503a30ab59860 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Thu, 7 Feb 2008 14:57:22 +0000
Subject: [PATCH] Utilities: Added transposeArray-function.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@261 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Utilities.php | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 068428bb9..938a06d47 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -410,6 +410,34 @@ class SimpleSAML_Utilities {
 		/* End script execution. */
 		exit;
 	}
+
+
+	/**
+	 * This function transposes a two-dimensional array, so that
+	 * $a['k1']['k2'] becomes $a['k2']['k1'].
+	 *
+	 * @param $in   Input two-dimensional array.
+	 * @return      The transposed array.
+	 */
+	public static function transposeArray($in) {
+		assert('is_array($in)');
+
+		$ret = array();
+
+		foreach($in as $k1 => $a2) {
+			assert('is_array($a2)');
+
+			foreach($a2 as $k2 => $v) {
+				if(!array_key_exists($k2, $ret)) {
+					$ret[$k2] = array();
+				}
+
+				$ret[$k2][$k1] = $v;
+			}
+		}
+
+		return $ret;
+	}
 }
 
 ?>
\ No newline at end of file
-- 
GitLab