Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Member Cranavvo's Avatar
    Join Date
    Sep 2013
    Location
    St. Helens, England
    Posts
    70
    Member #
    37189
    Liked
    11 times

    PHP Tutorial 3 - Functions


    This is a follow-up to my previous tutorial: PHP Tutorial 2 - Variables. It's wise you should read the last tutorial before you come onto the next one.

    PHP comes with loads of powerful functions which can help your code grow and expand and be used to its full potential, but what is PHP doesn't have the function you're really looking for, and you know what you want the function to do? In PHP you can make your own functions easily. For the sake of the tutorial, I want to make a calculator.

    PHP Code:
    <?PHP
    function Calculator($intval1$intval2){

    }
    ?>
    Every function, even if doesn't need variables, must have the brackets on the end of the function name. The variable within the brackets are called parameters and get their value from the variables places into the function when it's called. They're also in order of placement so when a variable is in the first part intval1 is now that variable's value, for e.g.

    PHP Code:
    <?PHP
    function Calculator($intval1$intval2){
    echo 
    $intval1 "<br />";
    echo 
    $intval2 "<br /><br />";
    }

    Calculator(1211);
    Calculator(1112);
    ?>

    12
    11

    11
    12
    In functions you can have the option to "return;" values, this is more commonly used when you "echo;" a function for e.g.

    PHP Code:
    <?PHP
    function Calculator($intval1$intval2){
    return 
    $intval1 " plus " $intval2;
    }

    echo 
    Calculator(1211);
    ?>

    12 plus 11
    That's all I can really say about what functions can do. There's a mass majority of functions built into PHP that can be used and adapted. If you ever need to find a function within PHP use the manual: PHP: PHP Manual - Manual. Thanks for reading.

  2.  


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:58 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com