Results 1 to 6 of 6

Thread: What are the PHP Variables?

  1. #1
    Join Date
    Aug 2006
    Posts
    122

    What are the PHP Variables?

    Hi friends,
    I am very new to the PHP. I have recently started doing the PHP. I don't know why the variables are used in PHP.?? Can someone explain me what are the PHP variables.? Also if possible, give me some example of PHP that is using the variable. Since, I am new, please don't give some tough example. Any other information regarding the variables are warmly welcomed.! So please help me to clear my doubt.!!
    In the end, we will remember not the words of our enemies, but the silence of our friends.
    -Martin Luther King Jr.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: What are the PHP Variables?

    Variables can be defined as an identifiers to the memory location to store data. You can create any number of variables. In PHP all the variables begin with a dollar sign "$". PHP has no limit on the length of variable name as in the case of other programming languages. The variable name must start with a letter or underscore. The variable name must be a combination of letters, numbers and underscores. Other characters such as *, +, #, @ are not allowed and causes error if used.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: What are the PHP Variables?

    All variables in PHP start with a $ sign symbol.The correct way of declaring a variable in PHP:
    Code:
    $var_name = value;
    Let's try creating a variable containing a string, and a variable containing a number:
    Code:
    <?php
    $txt="Hello World!";
    $x=20;
    ?>

  4. #4
    Join Date
    Nov 2005
    Posts
    1,323

    Re: What are the PHP Variables?

    Variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $a_car and $A_car are different variables in PHP's point of view. Also PHP does not require variables to be declared before being initialized. Here is an example of that :
    Code:
    <?php
    $hello = "Hello World!";
    $a_number = 5;
    $anotherNumber = 10;
    ?>
    If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What are the PHP Variables?

    You will have to follow some rules while writing a variable in PHP. I have mentioned the naming rules that are used for the variables :
    • A variable name can only contain alpha-numeric characters and underscores. Like a-z, A-Z, 0-9, and _ .
    • A variable name in PHP must start with a letter or an underscore "_".
    • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore. Like if you want variable my number, you can write it as $my_number and in capitalization as $my_Number.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: What are the PHP Variables?

    In PHP all the variables begin with a dollar sign "$" and the value can be assigned using the "=" operator as shown in following example :
    Code:
    $Name, $Name1, $First_Name, $Last_Name
    $Name = "MiKe";
    $Age = 22;
    The other important thing in PHP is that all the statements must end with a semicolon ";". In PHP we needn't have to specify the variable type, as it takes the data type of the assigned value.

Similar Threads

  1. What is tuple variables in SQL?
    By Shophia_D in forum Software Development
    Replies: 3
    Last Post: 26-11-2009, 12:51 PM
  2. Constant Variables in C++
    By Gomeler in forum Software Development
    Replies: 3
    Last Post: 19-11-2009, 09:11 AM
  3. Flash Variables to ASP
    By Mindstorm in forum Software Development
    Replies: 3
    Last Post: 31-10-2009, 06:07 PM
  4. Variables in .bat files
    By jackz in forum Software Development
    Replies: 3
    Last Post: 30-07-2009, 10:33 PM
  5. c# environment variables
    By EULALIA in forum Software Development
    Replies: 3
    Last Post: 13-07-2009, 02:23 PM

Tags for this Thread

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
  •  
Page generated in 1,714,117,750.22053 seconds with 17 queries