note 111943 added to function.array-chunk
| From: | Anonymous | Date: | Tue, 16 Apr 2013 04:47:31 +0000 |
| Subject: | note 111943 added to function.array-chunk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194487@lists.php.net to get a copy of this message | ||
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]]
?>
----
Server IP: 69.147.83.199
Probable Submitter: 75.70.34.207
----
Manual Page -- http://php.net/manual/en/function.array-chunk.php
Edit -- https://master.php.net/note/edit/111943
Del: integrated -- https://master.php.net/note/delete/111943/integrated
Del: useless -- https://master.php.net/note/delete/111943/useless
Del: bad code -- https://master.php.net/note/delete/111943/bad+code
Del: spam -- https://master.php.net/note/delete/111943/spam
Del: non-english -- https://master.php.net/note/delete/111943/non-english
Del: in docs -- https://master.php.net/note/delete/111943/in+docs
Del: other reasons-- https://master.php.net/note/delete/111943
Reject -- https://master.php.net/note/reject/111943
Search -- https://master.php.net/manage/user-notes.php