Engineers Gallery

PHP Variables

Variables are “containers” for storing information.


Creating (Declaring) Variables

[sam id=”4″ codes=”true”]

 

In PHP, a variable starts with the $ sign, followed by the name of the variable:

[nextpage title=”Program” ]

[message_box color=”yellow”]

<html>

<body>

<?php

$txt=”Hello Engineers!!”;

$x=5;

$y=6.5;

echo $txt;

echo “<br>”;

echo $x;

echo “<br>”;

echo $y;

?>

</body>

</html>

[/message_box]
[/nextpage]

[nextpage title=”Output” ]

[message_box color=”yellow”]

Hello Engineers!!

5

6.5

[/message_box]
[/nextpage]

After the execution of the statements above, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 6.5.

Note:- when you assign text value to variable,puts quotes around the value


 

PHP Variables

A variables can have sort name (like x and y) or one more descriptive names (age,total,value).

Rules for PHP variables:

Remember  that php variables names are case sensative !!!


 

 

Exit mobile version