Page 1 of 1
So, back to my function(1) question...
Posted: Wed Aug 28, 2002 8:19 pm
by phice
ok, I've got the switch($functionVariable); working. Now, what if I want to use two different variables inside my function()? is this possible?
In example, my user wanted 2 rows, and 3 collumns, and all they would have to do is function(2,3)..?
Posted: Wed Aug 28, 2002 8:23 pm
by fatalcure
yea, bascially:
Code: Select all
function myFunction($var1, $var2) {
echo "$var1 - $var2";
}
myFunction(1,2);
Posted: Wed Aug 28, 2002 8:31 pm
by hob_goblin
Code: Select all
function foo($x,$y){
for($i = 0; $i < $x; $i++){
echo '<tr>';
for($n = 0; $n < $y; $n++){
echo '<td>column</td>';
}
echo '</tr>';
}
}
Posted: Wed Aug 28, 2002 8:39 pm
by phice
wow.. that makes my coding so much easier... thanks ;D
Posted: Wed Aug 28, 2002 8:40 pm
by phice
hob_goblin wrote:Code: Select all
function foo($x,$y){
for($i = 0; $i < $x; $i++){
echo '<tr>';
for($n = 0; $n < $y; $n++){
echo '<td>column</td>';
}
echo '</tr>';
}
}
I was using tables as an example, but thanks. ^_^

Posted: Wed Aug 28, 2002 9:58 pm
by phpPete
You can always give default values in the function
Code: Select all
function getTable($numRows=5, $numCells=5, $bgcolor="#FFEECC")
{
$t = "<table bgcolor=" . $bgcolor . ">";
for($i =0; $i <= $numRows; $i++)
{
$t .= "\n<tr>\n";
for($j = 0; $j <= $numCells; ++$j)
{
$t .= "<td>ї" . $i . ' ' . $j . "]</td>";
}
$t .= "\n</tr>";
}
$t .= "\n</table>\n";
return $t;
}
$v = getTable();
$vv = getTable( 8, 4, "#FFGGEE" );
print($v);
print($vv);