note 94765 added to function.sort

From: Date: Mon, 23 Nov 2009 23:57:34 +0000
Subject: note 94765 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-163215@lists.php.net to get a copy of this message
<?php /** * function: array_columns * author: Brecht Cloetens * params: $a = array() // original array * $c = int() // number of columns */ function array_columns(&$a, $c=2) { $m = ceil(count($a)/$c); $j = 0; for($i=0; $i<$m; $i++) { for($k=0; $k<$c; $k++) { $key = $i+($m*$k); settype($key,'integer'); if(array_key_exists($key,$a)) { $b[$j] = $a[$key]; $j++; } } } $a = $b; } $arr = range('a','z'); array_columns($arr,4); print_r($arr); ?> Example: array(1,2,3,4,5) will be converted to array(1,4,2,5,3); This can be easy if you want to display an array into a specified number of columns. <table> <tr> <td>$arr[0] => 1</td> <td>$arr[1] => 4</td> </tr> <tr> <td>$arr[2] => 2</td> <td>$arr[3] => 5</td> </tr> <tr> <td>$arr[4] => 3</td> <td></td> </tr> </table> ---- Server IP: 217.71.118.186 Probable Submitter: 84.192.123.88 ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- https://master.php.net/note/edit/94765 Del: integrated -- https://master.php.net/note/delete/94765/integrated Del: useless -- https://master.php.net/note/delete/94765/useless Del: bad code -- https://master.php.net/note/delete/94765/bad+code Del: spam -- https://master.php.net/note/delete/94765/spam Del: non-english -- https://master.php.net/note/delete/94765/non-english Del: in docs -- https://master.php.net/note/delete/94765/in+docs Del: other reasons-- https://master.php.net/note/delete/94765 Reject -- https://master.php.net/note/reject/94765 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163215) next »