note 71475 added to ref.array
| From: | jordi at osu1 dot php dot net | Date: | Thu, 30 Nov 2006 16:10:33 +0000 |
| Subject: | note 71475 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120189@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 195.136.184.34
Probable Submitter: 83.145.176.25
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/71475
Del: integrated -- https://master.php.net/note/delete/71475/integrated
Del: useless -- https://master.php.net/note/delete/71475/useless
Del: bad code -- https://master.php.net/note/delete/71475/bad+code
Del: spam -- https://master.php.net/note/delete/71475/spam
Del: non-english -- https://master.php.net/note/delete/71475/non-english
Del: in docs -- https://master.php.net/note/delete/71475/in+docs
Del: other reasons-- https://master.php.net/note/delete/71475
Reject -- https://master.php.net/note/reject/71475
Search -- https://master.php.net/manage/user-notes.php