note 86743 added to function.array-map
| From: | radist-hack at yandex dot ru | Date: | Sat, 01 Nov 2008 21:37:35 +0000 |
| Subject: | note 86743 added to function.array-map | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-146023@lists.php.net to get a copy of this message | ||
To transpose rectangular two-dimension array, use the following code:
array_unshift($array, null);
$array = call_user_func_array("array_map", $array);
If you need to rotate rectangular two-dimension array on 90 degree, add the following line before or
after (depending on the rotation direction you need) the code above:
$array = array_reverse($array);
Here is example:
<?php
$a = array(
array(1, 2, 3),
array(4, 5, 6));
array_unshift($a, null);
$a = call_user_func_array("array_map", $a);
print_r($a);
?>
Output:
Array
(
[0] => Array
(
[0] => 1
[1] => 4
)
[1] => Array
(
[0] => 2
[1] => 5
)
[2] => Array
(
[0] => 3
[1] => 6
)
)
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/function.array-map.php
Edit -- https://master.php.net/note/edit/86743
Del: integrated -- https://master.php.net/note/delete/86743/integrated
Del: useless -- https://master.php.net/note/delete/86743/useless
Del: bad code -- https://master.php.net/note/delete/86743/bad+code
Del: spam -- https://master.php.net/note/delete/86743/spam
Del: non-english -- https://master.php.net/note/delete/86743/non-english
Del: in docs -- https://master.php.net/note/delete/86743/in+docs
Del: other reasons-- https://master.php.net/note/delete/86743
Reject -- https://master.php.net/note/reject/86743
Search -- https://master.php.net/manage/user-notes.php