Jump to content
Welcome, Guest
Existing user? Sign In

Sign In



Sign Up
The MatriX
  • Welcome To Ghbsys
  • CS GO Streaming Version is released. Have fun streaming while cheating!
  • Have a Payment Issue? Send us a Support ticket.
  • Make a thread if you need support or join our discord for live support.
  • Have Suggestions? Make a thread and you'll earn Ghbsys Points for implemented suggestions.
  • Join our discord to stay well connected! Don't forget to integrate your discord to the site
  • Welcome to [GHB] - GAmEhAcKbAsTaRdS Forum

    Welcome to [GHB] - GAmEhAcKbAsTaRdS Forum, like most online communities you must register to view or post in our community, but don't worry this is a simple free process that requires minimal information for you to signup. Be apart of [GHB] - GAmEhAcKbAsTaRdS Forum by signing in or creating an account.
    • Start new topics and reply to others
    • Subscribe to topics and forums to get email updates
    • Get your own profile page and make new friends
    • Send personal messages to other members.

    PHP Beginners Guide #1: Variables


    Yearupie
     Share

    Recommended Posts

    Best Forumer,

     

    I would like you to explain how php works, many people think they know something about PHP, but it is often not correct. Let's start with the basics!

     

    Chapter 1: Variables

     

    § 1: Introduction

    Variables can be used to temporarily store data. Such information may consist of numbers (integers) or pieces of text (strings), but can also be true / false data (booleans) or a set of data (array) contain. All we can create in PHP, we can put in a variable.

     

    § 2: Creating variables

    Creating a variable, also called declaration, done by one U.S. dollars sign ($) followed by a random name. With the equal-to (=) sign, we can then assign a value to the variable. Finally, we close the line with a semicolon.

     

    <?php 
    $text = 'Hello World!'; 
    echo $text; 
    ?>

     

    This piece of code we declare the variable $text, adding the value "Hello World!" to it. Then we use an echo to the contents of $text to put on screen. The output is as follows:

     

    Hello World!

     

    § 3: different types of variables

     

    As I mentioned earlier, we can actually save everything in a PHP variable. Depending on the content of a variable belongs to a particular type. Some examples:

     

    <?php 
    $text = 'Hello World!'; // String 
    $age = 28; // Integer 
    $price = 190.75; // Float 
    $check = false; // Boolean 
    ?>

     

    Here are some examples of different types of variables. The first variable $text we have already seen and contains a string. If you store numbers in one variable, it is an integer, a float if you concern about the numbers have decimal. If a variable includes true or false, you call it a boolean. A type variable that is not in this example is the array. On this variable I will make a separate tutorial.

     

    As we will see a string in PHP is placed between single quotes. In an integer, float or boolean we do not use quotes!

     

    § 4: Calculating with variables

    We have already seen that we can echo variables, but that's not all. Calculating with variables in PHP is something that we will use frequently. Some examples:

     

    <?php 
    $amout = 10; 
    $price = 9.95;
    $btw = 0.19; // 19%  
    
    $subtotal = $amout * $price; // Calculate subtotal
    echo 'Subtotal: '.$subtotal.'<br />'; 
    
    $aBtw = $subtotal * 0.19; // aBtw = After BTW		Calculate BTW
    $total = $subtotal + $aBtw; // Calculate Total
    echo 'Total: '.$total; 
    ?>

     

    Output:

    Subtotal: 99.5

    Total: 118.405

    Link to comment
    Share on other sites

    Guest
    This topic is now closed to further replies.
     Share

    • Recently Browsing   0 members

      • No registered users viewing this page.
    ×
    ×
    • Create New...