note 71475 deleted from ref.array by nlopess

From: Date: Thu, 15 Feb 2007 13:20:16 +0000
Subject: note 71475 deleted from ref.array by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-123432@lists.php.net to get a copy of this message
Note Submitter: jordi ---- hi, my function creates 2-Dimensional array ( matrix ) from an Array. I wrote it for easier defining <?php //CODE //rows - number of rows //columns - number of cols //values - array with values function dwuwym($rows, $columns, $values){ for ($i=0 ; $i<$rows; $i++){ for ($j=0 ; $j<$columns; $j++){ $matrix[$i][$j]=$values[$i*$columns+$j] ; } } return $matrix; } //USE $a=array(1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,); $tablica =dwuwym(2,8,$a); // GIVES // 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | // 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $tablica =dwuwym(4,4,$a); // GIVES // 1 | 2 | 3 | 4 | // 5 | 6 | 7 | 8 | // 1 | 2 | 3 | 4 | // 5 | 6 | 7 | 8 | $tablica =dwuwym(3,3,$a); // GIVES // 1 | 2 | 3 // 4 | 5 | 6 // 7 | 8 | 1 ?>

« previous php.notes (#123432) next »