note 115058 added to function.array-chunk

From: Date: Tue, 20 May 2014 10:51:29 +0000
Subject: note 115058 added to function.array-chunk
Groups: php.notes 
Request: Send a blank email to php-notes+get-199577@lists.php.net to get a copy of this message
Couldn't get the array_chunk_values() working, so ended up with this implementation: <?php function array_chunk_columns($data, $num_columns) { $n = count($data); $per_column = floor($n / $num_columns); $rest = $n % $num_columns; $columns = array(); $index = 0; for ($i = 0; $i < $num_columns; $i++) { // Add an extra item to each column while the column number is less than the // remainder. $add_rest = ($rest && ($i < $rest)) ? 1 : 0; $number = $per_column + $add_rest; $columns[] = array_slice($data, $index, $number); $index += $number; } return $columns; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 109.202.128.38 ---- Manual Page -- http://php.net/manual/en/function.array-chunk.php Edit -- https://master.php.net/note/edit/115058 Del: integrated -- https://master.php.net/note/delete/115058/integrated Del: useless -- https://master.php.net/note/delete/115058/useless Del: bad code -- https://master.php.net/note/delete/115058/bad+code Del: spam -- https://master.php.net/note/delete/115058/spam Del: non-english -- https://master.php.net/note/delete/115058/non-english Del: in docs -- https://master.php.net/note/delete/115058/in+docs Del: other reasons-- https://master.php.net/note/delete/115058 Reject -- https://master.php.net/note/reject/115058 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199577) next »