note 111943 deleted from function.array-chunk by googleguy
| From: | googleguy@php.net | Date: | Tue, 16 Apr 2013 05:13:20 +0000 |
| Subject: | note 111943 deleted from function.array-chunk by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194488@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
array_chunk is great for breaking something into rows of n cells that should be read from
left-to-right, top-to-bottom.
If you want to transpose it (that is, read from top-to-bottom, left-to-right), you can use the
following (keys are not preserved):
<?php
$a = [1,2,3,4,5,6,7,8,9];
$a = call_user_func_array('array_map', array_merge(null, array_chunk($a, 3)));
# $a = [[1,4,7],[2,5,8],[3,6,9]]
?>