Jump to content


is it posabel to do function name(){code}


4 replies to this topic

#1 kcd

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 17 November 2005 - 09:27 AM

I know you can do this with many types of code but i havent fond how to with php.
Can you.
Something like this.
function main()
{echo "This is main function";}

#2 adam123

    Retired P2L Staff

  • Members
  • PipPipPipPip
  • 2,306 posts
  • Location:London, UK
  • Interests:Programming and stuff.

Posted 17 November 2005 - 11:45 AM

Do you mean write your own functions? yes it's possible :)

You enter the code pretty much as you have and then call the function as you would with any other:

function main()
{
echo "This is main function";
}

main();

To avoid problems, make sure your function's name is not the same as that of a function built in to php :D

#3 kcd

    Young Padawan

  • Members
  • Pip
  • 10 posts

Posted 17 November 2005 - 11:48 AM

It dont work for me this is for php.
""Sorry my bad i gess it dose work tx i never knew""

Edited by kcd, 17 November 2005 - 11:51 AM.


#4 Chaos_Blader

    Young Padawan

  • Members
  • Pip
  • 18 posts

Posted 19 November 2005 - 07:16 PM

That wont work you will have to use

function main() {
return "This is A Main Function";
}

echo main();


or


function shout(shout) {
return shout;
}

echo shout("Hello World!");


#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 19 November 2005 - 08:07 PM

Actually, it will work just fine. What won't work is your second piece of code due to the fact that you never used $'s for your variables.

If you don't believe me, try for your self, or read what php.net has to say
http://php.net/manua...e.functions.php





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users