Sinisterly
Tutorial [PHP] Tutorial Five Basic Functions - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: PHP (https://sinister.li/Forum-PHP)
+--- Thread: Tutorial [PHP] Tutorial Five Basic Functions (/Thread-Tutorial-PHP-Tutorial-Five-Basic-Functions)



[PHP] Tutorial Five Basic Functions - KyleFYI - 02-21-2013

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.


RE: [PHP] Tutorial Five Basic Functions - w00t - 02-21-2013

Basic programming tells me you can't call functions you have yet to create.


RE: [PHP] Tutorial Five Basic Functions - i0xIllusi0n - 02-21-2013

(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.


RE: [PHP] Tutorial Five Basic Functions - KyleFYI - 02-21-2013

(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?


RE: [PHP] Tutorial Five Basic Functions - w00t - 02-23-2013

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.


RE: [PHP] Tutorial Five Basic Functions - KyleFYI - 02-23-2013

(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


RE: [PHP] Tutorial Five Basic Functions - cxS - 02-27-2013

(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++...