Variables in php

Php variables start with the symbol $ followed by the name of the variable 

eg: $jino, $cspsyco, $php etc.

Actually we did not need to declare a variable before using it. If we want to declare any values to a variable then we must declare it at anywhere in the program.

Declaring a variable in php


We can declare a numeric value or a string value at the time of declaration. String values should be declared within double quotes.


<html>
<head>
</head>
<body>
<?php
$a="Hello World";
echo "output is $a\n";
echo "output is".$a;
?>
</body>
</html>


Output

output is Hello World
output is Hello World


Here both of the echo will produce same output. We can set the variable for printing the output in these given two ways.

We can also perform operations using these variables.

<html>
<head>
</head>
<body>
<?php
$a=2;
$b=3;
echo $a+$b;
?>
</body>
</html>


Output

5


Concatenation of two strings

Strings in php can be concatenated using the period symbol(.). This will append two strings together.

<html>
<head>
</head>
<body>
<?php
$a="Hello";
$b="World";
echo $a.$b;
?>
</body>
</html>


Output

Hello World


Prev
Next

Comments

Popular posts from this blog

Node.js Cheat Sheet

Enhancing Supply Chain Security and Cloud-Native Development with Chainguard

Bootstrap ? What is it ?