note 56022 added to function.array-chunk
| From: | webmaster at cafe-clope dot net | Date: | Sat, 20 Aug 2005 23:27:29 +0000 |
| Subject: | note 56022 added to function.array-chunk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93971@lists.php.net to get a copy of this message | ||
based on the same syntax, useful about making columns :
<?php
function array_chunk_fixed($input, $num, $preserve_keys = FALSE) {
$count = count($input) ;
if($count)
$input = array_chunk($input, ceil($count/$num), $preserve_keys) ;
$input = array_pad($input, $num, array()) ;
return $input ;
}
$array = array(1, 2, 3, 4, 5) ;
print_r(array_chunk($array, 2)) ;
print_r(array_chunk_fixed($array, 2)) ;
?>
---- array_chunk : fixed number of sub-items ----
Array(
[0] => Array(
[0] => 1
[1] => 2
)
[1] => Array(
[0] => 3
[1] => 4
)
[2] => Array(
[0] => 5
)
)
---- array_chunk : fixed number of columns ----
Array(
[0] => Array(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array(
[0] => 4
[1] => 5
)
)
----
Manual Page -- http://www.php.net/manual/en/function.array-chunk.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56022
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56022&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56022&report=yes
Search -- http://master.php.net/manage/user-notes.php