note 30109 deleted from function.array-flip by bjori
| From: | bjori@php.net | Date: | Tue, 05 Aug 2008 18:25:17 +0000 |
| Subject: | note 30109 deleted from function.array-flip by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-143175@lists.php.net to get a copy of this message | ||
Note Submitter: rgonzalez at kidchile dot cl
----
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