function.php
Code: Select all
<?php
function process()
{
$value=$_POST['table'];
if(empty($value['row']))
{
$res="PLEASE ENTER ROWS";
}
elseif(empty($value['col']))
{
$res="PLEASE ENTER COLUMNS";
}
else
{
$x=$value['row'];
$y=$value['col'];
$res="<table border='1'>";
for($i=1;$i<=$x;$i++)
{
$res.="<tr>";
for($j=1;$j<=$y;$j++)
{
$res.="<td>$j</td>";
}
$res.="</tr>";
}
$res.="</table>";
}
return $res;
}
function table()
{
$res="<form action='table.php' method='post'>
<input type='text' name='table[row]'>ROW
<input type='text' name='table[col]'>COLUM
<input type='hidden' name='op' value='process'>
<input type='submit' value='SHOW TABLE'></form>";
return $res;
}
?>Code: Select all
<?php
include("function.php");
$opt=isset($_REQUEST['op']) ? $_REQUEST['op'] : null;
switch($opt)
{
case "process":
$html=process();
break;
default:
$html=table();
break;
}
?>
<html>
<head><title>TABLE</title></head>
<body>
<?php echo $html; ?>
</body>
</html>1-1,1-2,1-3,...
2-1,...
3-1,... and so on(depends on the entries).
I'm just curious about how to modify this code to change it from 1-D to 2-D arrays.
Thanks very much.