PHP Series-002-PHP Variables

                 PHP VARIABLES

Hi friends this is Revathi,In this blog,I want to share a informaton about php variable.
A variable is a means of storing a value, such as text string “Hello World!” or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value .

A variable is just a storage area. You put things into your storage areas (variables) so that you can use and manipulate them in your programs.
Suppose you want to catalogue your clothing collection. You enlist two people to help you, a man and a woman. These two people are going to be your storage areas. They are going to hold things for you, while you tally up what you own. The man and the woman, then, are variable.
 In php this variable may treated as,
  PHP define a variable with the following form:
$variable_name = Value;
If you forget that dollar sign($) , it will not work. This is a common mistake for new PHP programmers!

A system architecture for php variables


Case Sensitivity

php variable names are case-sensitive, so use the exact same capitalization when using a variable. The variables $a_number and $A_number are different variables in PHP
One thing that causes many problems and take hours of finding mistakes is case sensitivity.
For example,

$myVar = "PHP tutorial";
$myvar = "Variable";
echo "$myVar - $myvar"; //outputs "PHP tutorial-Variable"
?><span class="Apple-style-span">


PHP has a total of eight data types which we use to construct our variables:

The first five are simple types, and the next two (arrays and objects) are compound – the compound types can package up other arbitrary values of arbitrary type, whereas the simple types cannot support the arbitrary values of arbitrary type.

They are whole numbers, without a decimal point, like 4195. They are the simplest type they correspond to simple whole numbers, both positive and negative. Integers can be assigned to variables, or they can be used in expressions.
$int_var = 196
$another_int = -196 + 196;
Integer can be in decimal (base 10), octal (base 8), and hexadecimal (base 16) format. Decimal format is the default, octal integers are specified with a leading 0, and hexadecimals have a leading 0x.
They like 3.14159 or 49.1. By default, doubles print with the minimum number of decimal places needed. For example, the code:

$many = 2.2;
$many_2 = 2.3;
$out = $many + $many_2;
print($many + $many_2 = $out<br>.);<span class="Apple-style-span">

It produces the following output:
2.2 + 2.3 = 4.5
They have only two possible values either true or false.
For example,
if (TRUE)
print(“This will always print<br>”);
print(“This will never print<br>”);
NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this:
$my_var = NULL;
A variable that has been assigned NULL has the following properties:
· It evaluates to FALSE in a Boolean context.
· It returns FALSE when tested with IsSet() function.
They are sequences of characters is called a string. Following are valid examples of string,
$string_1 = “This is a string in double quotes”;
$string_2 = “This is a singly quoted string”;
$string_39 = “This string has thirty-nine characters”;
$string_0 = “”; // a string with zero character
Arrays are named and indexed collections of other values.
Objects are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
Example programs for php variable

$hello = "Hello World!";
$number = 4;
$Number1 = 8;
?&gt;&lt;span class="Apple-style-span" style="font-family: Consolas, Monaco, monospace; line-height: 18px; font-size: 12px; white-space: pre;"&gt;
$a = 2 + 1; //This sets the variable $a equal to 3 or (2 + 1)
$b = 3+ $a; //This sets the variable $b equal to 6, or (3 + $a)
?&gt;&lt;span class="Apple-style-span"&gt;

You may also like...

0 0 votes
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Anandkumar Pechimuthu
7 years ago

Very good article for beginners.

I like to know how to declare and assign value for array or object. Can you please provide with some example on that?

Would love your thoughts, please comment.x