More About PHP Variables

More About PHP Variables
When it comes to working with variables in PHP there are a few basics that you should keep fresh in your mind. Here we will discuss the types of PHP variables and a few rules you need to follow when naming your variables.

Naming Variables

  • The first rule is that variables begin with a dollar sign placed in front of the name of your variables. The dollar sign tells the server to treat this piece of code as a variable.

    $title_of_tutorial

  • The next rule is that the first character in the name of your variable must be a letter or an underscore. Although you can use numbers, letters and the underscore character _ when creating names for your variables, the first character in the name must be a letter or an underscore. A variable name can be any length.

    $tutorial_no2

  • The third rule is that variable names are case sensitive. That means that uppercase letters are considered different from lowercase letters. For example the variable name of Cat is not the same as the variable name cat. These two variable names are considered two different names.

    $Cat
    $cat

Types of Variables

  • There are two types of PHP variables. The first is a scalar variable. A scalar variable is a "simple" variable because it only contains one value. For example the variable $title_of_tutorial might be assigned the value of "More About PHP Variables".

    $title_of_tutorial = "More About PHP Variables";

  • The second type of variable is an array and it is a little more complicated. An array contains a list of values or another array. You can think of an array much like a tree. Each branch of the tree is a different value for the whole tree.

    $tree[0] = "first value";
    $tree[1] = "second value";
    $tree[2] = "third value";






This site needs an editor - click to learn more!



RSS
Editor's Picks Articles
Top Ten Articles
Previous Features
Site Map





Content copyright © 2023 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.