PHP – String with example



A string is can have letters, numbers, special characters and arithmetic values or combination of all.

Example: Hello World !

Example: Hello World ! 123

Above both example are string.

To assign a string to a variable is there is two way.

$string=‘Hello World !’;
$string_two=“Hello World !”;
 

You can use both single quotation or double quotation.But there is a small difference between single quotation and double quotation.

single quotation

Single quoted strings are the easiest way to specify string.
It is faster than double quotation.

Double quotation

Double quotes force PHP to specify the string.
It is less faster than single quotation.
So now in our mind a big confusion come that where to use single quotation and where to use double quotation.

Best example to under stand.

<?php
$a=‘Hello World';
echo $a;
?>
 

Output: Hello World