note 30109 added to function.array-flip

From: Date: Thu, 06 Mar 2003 17:58:21 +0000
Subject: note 30109 added to function.array-flip
Groups: php.notes 
Request: Send a blank email to php-notes+get-44946@lists.php.net to get a copy of this message
If you need traspose an array (i.e convert columns in rows) for a multidimensional array obtain from a SQL query, try this: That is an array from arrays that represent each columns. Array ( [col1] => Array ( [0] => 10 [1] => 100 [2] => 200 [3] => a ) [col2] => Array ( [0] => 1 [1] => 3 [2] => 2 [3] => 5 ) ) $arreglo_aux = Array(); foreach( $arreglo as $keymaster => $value ) foreach( $value as $key => $elemento ) $arreglo_aux[$key][$keymaster] = $elemento; the results will be Array ( [0] => Array ( [col1] => 10 [col2] => 1 ) [1] => Array ( [col1] => 100 [col2] => 3 ) [2] => Array ( [col1] => 200 [col2] => 2 ) [3] => Array ( [col1] => a [col2] => 5 ) ) Bye. Rodrigo González M. - CHILE -- http://www.php.net/manual/en/function.array-flip.php http://master.php.net/manage/user-notes.php?action=edit+30109 http://master.php.net/manage/user-notes.php?action=delete+30109 http://master.php.net/manage/user-notes.php?action=reject+30109

« previous php.notes (#44946) next »