PHP Variable@ Shwetank education.com
Definition –
Variables are used for storing values, like text strings, numbers or arrays.
Note
All variables in PHP start with a $ sign symbol.
The correct way of declaring a variable in PHP:
$var_name = value;
New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.
Syntax-
$hello=5;
$- sign must be start
Hello- is a variable name
5– is a variable value
Example
Let’s try creating a variable containing a string, and a variable containing a number:
<?php
$txt=”Shwetank Education!”;
$x=10;
?>
Example with Output
<?php
$hello=1001;
echo “hello”;
?>
PHP String@ Shwetank education.com
Definition –
String variables are used for values that contain characters.
A string can be used directly in a function or it can be stored in a variable.
the PHP script assigns the text “shwetank Education” to a string variable called $txt:
<?php
$txt=”shwetank Education”;
echo $txt;
?>
The output of the code above will be:
shwetank Education
The Concatenation Operator
The concatenation operator (.) is used to put two string values together.
To concatenate two string variables together, use the concatenation operator:
<?php
$txt1=”shwetank education”;
$txt2=”welcome to you!”;
echo $txt1 . ” ” . $txt2;
?>
The output of the code above will be:
shwetank education welcome to you!
The strlen() function
The strlen() function is used to return the length of a string.
Let’s find the length of a string:
<?php
echo strlen(“Shwetank Eucation!”);
?>
The output of the code above will be:
17