So, back to my function(1) question...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

So, back to my function(1) question...

Post 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)..?
Image Image
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

yea, bascially:

Code: Select all

function myFunction($var1, $var2) {
echo "$var1 - $var2";
}

myFunction(1,2);
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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;
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

wow.. that makes my coding so much easier... thanks ;D
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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
Image Image
User avatar
phpPete
Forum Commoner
Posts: 97
Joined: Sun Aug 18, 2002 4:40 pm
Location: New Jersey

Post 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);
Post Reply