Page 1 of 1

function functions :/

Posted: Fri Aug 09, 2002 12:21 am
by phice
ok. Lets say I've got a certain function. It's named function1()...

I've seen a script that allows the user to create an action that the function does, when putting in something like function1(4) does what 4 is specified to, and function1(7) does what 7 is specified to do...

How would I go about making something like that?

Need more info? just ask--

Posted: Fri Aug 09, 2002 1:40 am
by 9902468
Many ways to do it, heres one:


Code: Select all

function1($what_u_want){

   switch ($what_u_want) {
    case 0:

           /* Code here */        

    case 1:
        
         /* Code here */

   }


}

etc. You can also call other functions inside one function and again call another function inside that function....

check http://www.php.net/manual/en/control-st ... switch.php
for more

-9902468

Posted: Fri Aug 09, 2002 3:20 pm
by phice
Sweet :D Thank you very much ^_^

Posted: Thu Aug 15, 2002 10:51 pm
by phice

Code: Select all

<?
function haha($waht) &#123;
	switch($waht) &#123;
		case 1:
			echo "haha, foo<p>";
		case 2:
			echo "you tried to do 2 times! :/ <p>";
		case hahahehe:
			echo "you entered the hehehaha zone!<p>";
		&#125;
&#125;

haha(1);
haha(1);
haha(2);
haha(hahahehe);
haha(1);
?>
What it did: http://nncommunity.phpwebhosting.com/switchtest.php


Why........?

Posted: Thu Aug 15, 2002 10:56 pm
by protokol
You forgot to put break; statements in.

Code: Select all

function haha($waht) &#123;
   switch($waht) &#123;
      case 1:
         echo "haha, foo<p>";
         break; // need this
      case 2:
         echo "you tried to do 2 times! :/ <p>";
         break; // need this
      case hahahehe:
         echo "you entered the hehehaha zone!
         break; // need this<p>";
   &#125;
&#125;

Posted: Thu Aug 15, 2002 11:00 pm
by phice
I was thinking it was something like that ;/