PHP Tutorial 18 – Functions (PHP For Beginners)

PHP already holds hundreds of built-in functions that you use in your everyday applications, but in PHP you have the ability to create your own functions. A function will carry out a pre-determined set of code and can be called whenever you want it to. Functions can also take parameters so you can specify the data that is entered into a function each time you call it. Functions can also be used to return values. This video will cover the wonderful world of functions.

For more information, check out the website:

http://howtostartprogramming.com/PHP/php-tutorial-18-functions/

Comments

Allen W says:

Save it in a global variable (outside of the function).

$day = ‘Monday’
function updateDay($newDay){
$day = $newDay;
}
updateDay(‘Tuesday’);

The global variable is $day because it is outside of any method, this means that it will not be destroyed once the function ends. Then the newly updated $day can be used with the new value of ‘Tuesday’.

James Allen says:

Good job!

dashbyictfd says:

Have you checked if you have any other software using port 80 on your pc/mac?

Luka Lepi says:

mistake in coding at time 1:25  -.- ,  why do you use double echo ?? the functioun you created does not return any value, so you do not need to echo this “”   just call the function,  or change the function to return the value …

Jeremy Murphy says:

You should be posting the code you explain on your site…….Like the work..THX

rafalpilat145 says:

your wrong. parameter is pronounced “para-meter”

Quyền Đỗ says:

Your tutorial is easy to follow. What a great work! I admire you alot.

Craig Watson says:

Really pleased someone has gone to the effort of doing these videos, great teaching style really helping me with my studies.

subas khanal says:

I am confuse what is the difference between return and without return in the function ? and why they are important?

Asim Ahmed says:

why we use return value in function???

Shaun Steenson says:

Really great video’s for refreshing my mind after forgetting it all. Thanks!

Wheels List says:

Great work.Thanks for the tutorial.

Minor note: don’t say “That’s it” like the lesson is finished when you still have things to say. Say, “To recap, …” Only saying this because your teaching is already so good.

Bernadette Higgins says:

Superb!! I really like your calm and clear way of explaining. Thank you sooo much.

amaro19841 says:

good job man…i really learn something from your tut…

Modz Marvin says:

dude each and every video makes me feel more happy that i achualy understand wtf ur on about and i achualy can follow u!!! 10/10

I always tried to make a password section but couldnt till i watched these tutorials!. you will see me commenting on the last video u upload lol all the way!

jos vanherl says:

i really start to hate these wix advertisement.

Harsha's Python Guide says:

Thank You !!

Auranya says:

weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

thasha1 says:

keep doing more tutorial :)

Dhuha Al-Shaikhli says:

Thanks..well explained

Tantely says:

Chris your the best

Farooq Pasha says:

These tutorials are very useful and i want some more complex tutorials…
 

hotel says:

it’s because the function is a block statement, which means instead of being like a sentence ending with a period (or semicolon), it’s more like a paragraph, where it is defined by the brackets. I hope this helps 😀

pritom borogoria says:

Just awesome………..

lifehapad says:

The reason you do not need echo again when you call the function is you have print out the result to the screen under your function

Jeff Baker says:

Thanks but I’m confused.. “return” was not explained on any previous tutorials and I don’t understand what it was doing.. 

dewhite765 says:

In this tutorial for creating functions, the purpose of the functions in all of the examples was to perform the calculation and display it. What if you wanted to perform and calculation and return the output for use later in the program. Perhaps that is coming in a later tutorial.

nep808 says:

I think this is better:

function substract($num1, $num2){
    $num1 – $num2;
}

echo substract(5, 2);

Ekin Karayalcin says:

Great videos man, thanks! Just a quick info;

The welcome() function already echo’s the welcome message. Therefore, when calling the welcome() function, you don’t need to echo it a second time. Just tyipng welcome(); would be enough.

Keep up the good work!

christian paul agpuon says:

Please create a tutorial about functions that getting a input from a textbox and display the result.

JustMe says:

No need to apologize always 😛

shobhit says:

hi according to the tutorial the answer is 25  but when i m giving echo ‘the addition is ‘ . $num1+$num2;  then it is giving wrong answeri.e 15 …

Elias Poulsen says:

Why didn’t you just type welcome() instead of echo welcome()?

Akash Talokar says:

what does the functions.php file contains for the Real Time Project?

Krishnan Sethuraman says:

Chris thank you man. I have been trying to learn PHP from 2008. Could not. One day with your videos and I got a strong foundation in PHP. Above all you have kept it free. A person like me with less money and the desire to learn knows the value of it. Thanks buddy. God bless you.

Designer-Tamil says:

thanks 

Oli Tworkowski says:

Still didnt get what the curly brackets are good for :(

scipics sci says:

simple but creditable

yinimini mo says:

You are an excellent teacher

Modz Marvin says:

you MUST check your firewall. mine didnt work but got a request to unblock it as its using ports

WordOnWheels says:

i need help, i hope you are able to assist, i accidentally removed apart of the footer info in the function area and now lost my site after the update function got clicked, is there any way i can get my site back up again ? i have a copy of the stuff that was in the functions file, i copy and paste into notepad before the mistake happened, is there any way to get the web site back up and restore the function file back to normal and web site back up again ? your help would be very appreciative as its now worrying me as i no longer got access to my site

Chiranjeev Bansal says:

what is meant by return at #6:22

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours