AnimeGalleries [dot] NetAnimeWallpapers [dot] ComAnimeLyrics [dot] ComAnimePedia [dot] ComAnimeGlobe [dot] Com


User Tag List

Closed Thread
Results 1 to 5 of 5

Thread: [Tutorial - PHP] Variables and operators

  1. #1
    Copyright © 2013 FS FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD's Avatar
    Gil
    6,638.20
    Gender
    My Mood
    Lonely
    Gifts Fuuko Starfish Ice Cream Bamboo Cup
    Mentioned
    215 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    12-19-2023 07:16 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jun 2005
    Location
    I would like to know that too. O_o;;
    Age
    39
    Threads
    162
    Posts
    2,921
    Blog Entries
    5
    AW Wallpapers
    3
    Rep Power
    2200

    Default [Tutorial - PHP] Variables and operators

    PHP Tutorial - Variables and operators


    Variables

    Variables are containers. Think of an ordinary box that you put stuff into. That box may have a label on it so you remember what is inside of it. Variables are boxes that you put data information into. They are labeled with names.

    Once you have some information in variables, it can be sorted, organized, manipulated, and so forth.

    A variable name starts with a dollar ($) symbol. After that you can use any combination of higher case letters (A-Z), lower case letters (a-z), or the underscore (_). Numbers 0-9 can be used as well, but only after the dollar and a character. Spaces are not allowed. New PHP programmers often forget the dollar sign at the beginning of the variable. In that case it will not work.

    The correct way to declare variables in PHP:
    PHP Code:
    $var_name value;
    $varName value;
    $var_name30 value;
    $_var_name value
    The wrong way to declare variables in PHP:
    Code:
    $var name = value;
    var_name = value;
    $30vars = value;
    Variable names are CaSe SeNsItIvE. If you are referring to a variable in your coding, make sure the name matches exactly. $MyVariableName is different from $myvariablename.

    Variable names should be easy to understand. Give some thought into the names.
    $fn or $FirstName or $first_name
    Which one looks more easier to understand and remember?

    There are three types of variables.
    • Numbers
    • Strings
    • Arrays

    Numbers:
    Number variables may contain integers (regular positive or negative numbers) or floating-point (decimal) numbers. No fractions, letters, or extra decimals allowed.

    Example:
    PHP Code:
    $integer_example 5;
    $floating_point_example 365.25
    Strings:
    String variables are word variables. They may contain number information and other variables. The values of string variables are contained within single quotes (') or double quotes (") depending on how you want to use them.

    Example:
    PHP Code:
    $string_example_1 "This is a test.";
    $string_example_2 'This is another test.';
    $string_example_3 "5";
    $string_example_4 "The value is $integer_example.";
    $string_example_5 'The value is $integer_example.'
    The difference between single and double quotes is: single quotes will print out the exact value of the string as is, while double quotes will transfer variable values into place before printing.

    Example:
    PHP Code:
    print "$string_example_4 <br />";
    print 
    '$string_example_5'
    Returns:
    Code:
    The value is 5. 
    $string_example_5
    Arrays:
    Arrays are groups of variables. They are defined as a table with rows which can contain either numbers or strings. Arrays are defined with the array() function.

    Example:
    PHP Code:
    $my_first_array = array();
    $my_second_array = array(12"text1"3"text2"); 
    In the example above we created an empty array and an array filled with numbers and random text.

    Printing arrays is a little bit tricky, because if you print it the usual way:
    PHP Code:
    print $my_second_array
    You will get this output:
    Code:
    array()
    To get our value printed out we need to specify which row we want to print:
    PHP Code:
    print $my_second_array[2]; 
    This will return:
    Code:
    text1
    From our example above we can see each entry gets it's own row number, which we use to retrieve our data. The rows start with number 0, which means row 0 has value 1, row 1 has value 2, row 3 has value text1 and so forth.


    In PHP, a variable does not need to be declared before adding a value to it and it can be used over and over again in your script until the script runs. In the examples above, you see that you do not have to tell PHP which data type the variable is, either. PHP automatically converts the variable to the correct data type, depending on its value.


    Operators

    Operators are used to operate on values. With them you can assign, compare and combine numbers and strings.

    PHP uses 4 different types of operators:
    • Arithmetic Operators
    • Assignment Operators
    • Comparison Operators
    • Logical Operators

    Arithmetic Operators:
    Arithmetic operators are used for elementary mathematical operations.


    Assignment Operators:
    Assignment operators assign a value to the variable. The most used one is the equals (=) symbol.


    Comparison Operators:
    Comparison operators are used for comparison. They tell you if two numbers or strings are of the same value.


    Logical Operators:
    They will usually take two of the comparison operator conditions (above) and compare them to each other.


    This ends the second part of the PHP tutorial. Next time we will be discussing strings, numbers and arrays in detail.

    NOTE: Images taken from w3schools.com
    Last edited by FlashD; 08-15-2009 at 11:06 AM. Reason: Mistake found and fixed

  2. #2
    Banned Forum / Chat .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv's Avatar
    Gil
    14,160.46
    Gender
    Gifts Cookie 035 - Clefairy Manekineko
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    08-16-2010 10:28 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Oct 2007
    Threads
    44
    Posts
    834
    Blog Entries
    80
    Rep Power
    0

    Default

    How do you include layouts from HTML to PHP?

  3. #3
    Copyright © 2013 FS FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD's Avatar
    Gil
    6,638.20
    Gender
    My Mood
    Lonely
    Gifts Fuuko Starfish Ice Cream Bamboo Cup
    Mentioned
    215 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    12-19-2023 07:16 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jun 2005
    Location
    I would like to know that too. O_o;;
    Age
    39
    Threads
    162
    Posts
    2,921
    Blog Entries
    5
    AW Wallpapers
    3
    Rep Power
    2200

    Default

    There are many different ways to do so, but the easiest one is probably using the include function.

    PHP Code:
    include('index.html'); 

  4. #4
    Banned Forum / Chat .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv has a reputation beyond repute .fnhvmnvmv's Avatar
    Gil
    14,160.46
    Gender
    Gifts Cookie 035 - Clefairy Manekineko
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    08-16-2010 10:28 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Oct 2007
    Threads
    44
    Posts
    834
    Blog Entries
    80
    Rep Power
    0

    Default

    You only need this small code?
    I browsed all the time and found very ... confusing codes ... something with "footer" and "header"

    PHP Code:
     <?PHP include("header.php");?>
    PHP Code:
    <?PHP include("footer.php");?>

  5. #5
    Copyright © 2013 FS FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD has a reputation beyond repute FlashD's Avatar
    Gil
    6,638.20
    Gender
    My Mood
    Lonely
    Gifts Fuuko Starfish Ice Cream Bamboo Cup
    Mentioned
    215 Post(s)
    Tagged
    0 Thread(s)
    Latest Post
    12-19-2023 07:16 AM
    User Info Thanks / Tagging Info Gifts / Achievements / Awards vBActivity Stats
    Join Date
    Jun 2005
    Location
    I would like to know that too. O_o;;
    Age
    39
    Threads
    162
    Posts
    2,921
    Blog Entries
    5
    AW Wallpapers
    3
    Rep Power
    2200

    Default

    Yes, that's because the codes you have found are much more complex and don't just include stuff but also work with the included stuff.
    Header is only the top part of the webpage, while footer the bottom part. In the between, you put the content which is in the same file where you used the two includes.

    To make you an example:

    header.php content:
    PHP Code:
    print "This is the header!<br />"
    footer.php content:
    PHP Code:
    print "This is the footer!"
    index.php content:
    PHP Code:
    include('header.php');
    print 
    "Hello world<br />";
    include(
    'footer.php'
    index.php will return:
    Code:
    This is the header!
    Hello world
    This is the footer!
    So yes, include() is the only thing you need if you just want to include and not edit the file.
    Last edited by FlashD; 08-19-2009 at 06:31 AM. Reason: Reworded some parts

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. [Tutorial - Python] Part 0 - Getting started
    By Eris in forum Computers and Technology
    Replies: 4
    Last Post: 07-30-2009, 07:54 PM
  2. [Tutorial - Python] Part 1 - Variables and Code flow
    By Eris in forum Computers and Technology
    Replies: 1
    Last Post: 07-29-2009, 03:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts