Category: PHP Start

PHP Concatenation Operator Example

PHP Script:

<?php
$str1 = “Face”;
$str2 = “book”;
echo $str1 . “” . $str2;
?>

Output:

Facebook

Description:

is a concatenation operator in PHP and it is used to join two string values together

PHP String Variables Example

PHP Script:

<?php
$txt=”Hello world!”;
echo $txt;
?>

Output:

Hello world!

Description:

String variables are used to hold values that contain characters.

Note: Remember one thing that when you assign a text value to a variable put single or double quotes around the value.

PHP Variables Example

PHP Script:


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

Output:


11

Description:

Variables are like containers to store information
Here, $x hold value 5 and $y hold value 6
and the sum of values hold by $x and $y is assign to variable $z
now, the resultant value hold by $z is output to browser by echo statement.

Rules for Variables Naming:

1- Starting with Dollar $ character.
2- Variable names must be start with a letter or underscore character.
3- Variable name can be consist of numbers, letters, underscores but cannot include characters like + , - , % , ( , ) etc