#native_company# #native_desc#
#native_cta#

Convert Text into Multidimensional Array

By smirniotopoulos
on September 5, 2000

<? // Begin PHP processing;
echo "<body bgcolor=gray>";
///////////////////////////
// Function for reading a single dimension (column) array into a multiple dimension array
// Copyright 2000 by J.G. Smirniotopoulos
// Made available for non-commercial public use, provided this copyright attribution is intact
// Requires:
// 	$cols = number of columns for output array
//   	$buffers = single column array with cell values separated by commas ( , )
//
// NOTE: You can clearly organize your data into columns this way;
// The first row (0) can optionally be used for column headings;
// Each entry (line) must end with a comma ( , );
//
// SAMPLE Array using comma [,] as separator;
//
$buffers="
Numbers, Roman
Numerals, English, Greek, 1, I, one, ena, 2, II, two, dio, 3, III, three, tria, 4, IV, four, tecera ";// end string; $buff = explode (",", $buffers); //////////////////////////// // Create Multidimensional Array // // requires array $buff; // requires number of columns for output table $cols; $cols=4;// define number of columns here; function make_table($cols,$buff){ $rows=((count($buff))/$cols); // calculate number of rows; echo "Total Items = ".count($buff)."
"; echo "Columns = ".$cols."
"; echo "Total Rows = ".$rows."
"; echo "<table valign=top align=center border=2 bgcolor=blue>"; $item=0; while ($item < (count($buff))): for ($row=0; $row < $rows; $row++){ if (($row%2)==0){echo "<tr bgcolor=orange>";}else{echo "<tr bgcolor=yellow>";}; if ($row>0){ echo "<td>Row Number ". ($row)." </td>"; }else{ echo "<td>Column Titles ==></td>"; } for ($col=0; $col < $cols; $col++){ $myarray[$row][$col]=$buff[$item]; echo "<td>".$myarray[$row][$col] ;// optional display; // if ((($col+1)%$cols)!=0) { echo " - is associated with - "; };// optional display; echo "</td>"; $item++;// loop items; }// loop columns; echo "
"; echo "</tr>"; }// loop rows; endwhile ; echo "</table>"; }// end function make_table; make_table(4,$buff);// number of columns, input array; ////////////////////////// // End PHP processing; ?>