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++)&#123;
 echo '<tr>';
  for($n = 0; $n < $y; $n++)&#123;
   echo '<td>column</td>';
   &#125;
 echo '</tr>';
 &#125;
&#125;

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)&#123;
for($i = 0; $i < $x; $i++)&#123;
 echo '<tr>';
  for($n = 0; $n < $y; $n++)&#123;
   echo '<td>column</td>';
   &#125;
 echo '</tr>';
 &#125;
&#125;
I was using tables as an example, but thanks. ^_^ :D

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")
    &#123;
    $t = "<table bgcolor=" . $bgcolor . ">";
        for($i =0; $i <= $numRows; $i++)
            &#123;
                $t .= "\n<tr>\n";
                for($j = 0; $j <= $numCells; ++$j)
                &#123;
                    $t .= "<td>&#1111;" . $i . ' ' . $j . "]</td>";
                &#125;
                $t  .=  "\n</tr>";
            &#125;
            $t .= "\n</table>\n";
            return $t;
    &#125;
$v = getTable();
$vv = getTable( 8, 4, "#FFGGEE" );
print($v);
print($vv);