Login Register






Tutorial [PHP] Tutorial Five Basic Functions filter_list
Author
Message
[PHP] Tutorial Five Basic Functions #1
A function is just a neat way to call a script. This isn't the best way to explain but that's how I see it.

So let me give you an example on how to make and call a function

PHP Code:
<?PHP echo function_name(); //This will echo out the function. function function_name(){ //This is starting the function. $number1 = 1; $number2 = 2; $number3 = $number1 + $number2; return $number3; //To return the data back you need to put return then the data you want to return back! } ?>

This is how you would change the value of $number1 and $number2 without having to change the code.

PHP Code:
<?PHP $number1 = 1; $number2 = 2; echo function_name($number1, $number2); //As you see we are putting the strings in to the function. function function_name($number1, $number2){ //This is where you put the strings names to be called in the function. $number3 = $number1 + $number2; return $number3; //To return the data back you need to put return then the data you want to return back! } ?>

Note: If you need any help and I have not yet made a tutorial for it please visit php.net.

Reply

RE: [PHP] Tutorial Five Basic Functions #2
Basic programming tells me you can't call functions you have yet to create.

Reply

RE: [PHP] Tutorial Five Basic Functions #3
(02-21-2013, 07:43 AM)w00t Wrote: Basic programming tells me you can't call functions you have yet to create.

echo name();

name() { }

It is created.
[Image: BAvhP6h.png]
Code:
[5:42:25 PM] i0xillusi0n: Breshie don't bust a nut over chloe now [5:42:31 PM] Entity: fapfapfapfapfapfapfapfapfapfap [5:42:33 PM] Jigglypuff | SL: EWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW

Reply

RE: [PHP] Tutorial Five Basic Functions #4
(02-21-2013, 07:43 AM)w00t Wrote: Basic programming tells me you can't call functions you have yet to create.

Point of this post?

Reply

RE: [PHP] Tutorial Five Basic Functions #5
You call the function before declaring it. Unless PHP is different than every language I've worked with, that doesn't work, the function needs to be made before it's called.

Reply

RE: [PHP] Tutorial Five Basic Functions #6
(02-23-2013, 05:10 PM)w00t Wrote: You call the function before declaring it. Unless PHP is different than every language I've worked with, that doesn't work, the function needs to be made before it's called.

Doesn't matter with PHP. Script works fine as well Tongue

Reply

RE: [PHP] Tutorial Five Basic Functions #7
(02-23-2013, 05:10 PM)w00t Wrote: You call the function before declaring it. Unless PHP is different than every language I've worked with, that doesn't work, the function needs to be made before it's called.

PHP is not like C++...
-- cxS

[ Haskell/.NET/C/C++ - Software Engineer ]

Reply