note 30109 modified in function.array-flip by vrana

From: Date: Tue, 17 Aug 2004 13:58:20 +0000
Subject: note 30109 modified in function.array-flip by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79986@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 ) ) <?php $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 --was-- 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://php.net/manual/en/function.array-flip.php

« previous php.notes (#79986) next »