function functions :/

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:

function functions :/

Post 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--
Image Image
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

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

Post by phice »

Sweet :D Thank you very much ^_^
Image Image
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post 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........?
Image Image
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

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

Post by phice »

I was thinking it was something like that ;/
Image Image
Post Reply