Arrow

PHP variables

AuthorHariom Prajapati

Pubish Date24 Jul 2022

categoryPHP

PHP variables are containers, which use to storing information.

A variable starts with the dollar sign ($) in PHP, then write the variable name.

 

Syntax -

<?php
$variable_name = "Hello Dear!";
echo $variable_name // to print
?>

 

Example 1

<!DOCTYPE html>
<head>
  <title>Document</title>
</head>

<body>

<h4>PHP variables</h4>

<?php
$myfirstname = "sumit";
$mylastname="sarkar";
echo "$myfirstname"." "."$mylastname"
?>

</body>

</html>

 

Output

php variables

Example 2

<!DOCTYPE html>
<head>
  <title>Teknowize</title>
</head>

<body>

<h4>PHP variables</h4>

<?php
$x = 5;
$y = 4;
echo $x + $y;
?>

</body>

</html>

 

Output

php variables

Example 3

<!DOCTYPE html>
<head>
  <title>Document</title>
</head>

<body>

<h4>PHP variables</h4>

<?php
$firstname="sumit";
echo "$firstname"." dey" ." sarkar"
?>

</body>

</html>

 

Output

php variables