Entry
how do I transform a database table with x columns into an array (a matrix) for passing it to an output-print function?
Feb 17th, 2001 09:23
christian metzler,
<?
/**********************************************
* solved previous question myself: see example
*
* build a two dimensional array in a function and
* return the contents to the calling function
*
*/
function make_array(&$matrix)
{
print("************make_array************************\r\n");
$row = array(); // populate row; for example from a db query
for ($i=0,$j=0,$k=0;$i<10;$i++,$j++,$k++)
{
$row[0] = "i".$i;
$row[1] = "j".$j;
$row[2] = "k".$k;
$matrix[$i] = $row;
}
for ($i=0;$i<10;$i++)
{ //output the array for testing purposes
printf("matrix[%d]=
%s,%s,%s\r\n",$i,$matrix[$i][0],$matrix[$i][1],$matrix[$i][2]);
}
print_r ($matrix); //print human readable, list complete array
return(1);
}
/*****************************************
* pass array reference, get result array
*/
$m=array(); // declare array
if(make_array($m)) print("**called_make_array()--SUCCESS--\r\n");
print_r ($m);
?>