PHP has lots many things to do, you can explore the many thing in PHP for your web development. PHP
To learn PHP, we have to understand some basics behind the PHP.
That it, how to write PHP? How to make comment? I.e. To hide from complier and readable in program pan, Variable declaration, syntax, operators etc.,
Let’s see how to make a comment.
Comment in PHP
Comment using * asterisk mark
Comment using double foreword slash // & hash # sign, comment using this sign called as single line comment
<!DOCTYPE html>
<html>
<body>
<?php
<body>
<?php
/*
Use of forward slash with asterisk mark is Multi-line comment. You can use if your to add for your program description or whenever is necessary, all the comments or code written inside the comment will not be complied by php compiler.
*/
// Here, I am using double forward slash; this is a single line comment.
# Here, I am using only hash sign, this is also a single line comment.
# Here, I am using only hash sign, this is also a single line comment.
?>
</body>
</html>
</body>
</html>
Variable declaration in PHP
PHP has its own unique style to declare the variables. PHP does not have any predefined notation to declare the type of variable for example , number , text etc. its advantage of disadvantage that clearly depends on your thinking.
The moment when you assign some value to that variable , then that variable becomes that type variable. PHP is uses “Dollar” Sign ($) to declare any variable. User this $ sign as prefix to every alphanumeric character.
Note 1 : Variable don't accepts hyphens , space and numeric start.
Notes 2 : PHP statement always ends with semicolon.
Notes 3 : Without quotes text Variable value should be only number and it should not be text.
Below are NOT valid declarations.
$2carname="BMW" ;
$2car-name="BMW";
$2car name="BMW";
$2carname=BMW ;
Below are the valid declarations.
$carname="BMW" ;
$car_name="BMW" ;
$car_2name="BMW" ;
The moment when you assign some value to that variable , then that variable becomes that type variable. PHP is uses “Dollar” Sign ($) to declare any variable. User this $ sign as prefix to every alphanumeric character.
Note 1 : Variable don't accepts hyphens , space and numeric start.
Notes 2 : PHP statement always ends with semicolon.
Notes 3 : Without quotes text Variable value should be only number and it should not be text.
Below are NOT valid declarations.
$2carname="BMW" ;
$2car-name="BMW";
$2car name="BMW";
$2carname=BMW ;
Below are the valid declarations.
$carname="BMW" ;
$car_name="BMW" ;
$car_2name="BMW" ;
Sample code:
<!DOCTYPE html>
<html>
<body>
<?php
<html>
<body>
<?php
$a=10; // Variable $a is declared and value 10 is assigned to it
$b=20; // Numeric variable $b as declared
$c=null; // Variable declared $c as null, null is assigned to variable $c
?>
</body>
</html>
</body>
</html>
Is variable case sensitive in PHP? Yes
Is variable case sensitive in PHP? Yes, it’s true; variables are case sensitive in PHP.
You can create same name variables by changing its case.
Sample Code:A
<! DOCTYPE html>
<html>
<body>
<?php
$x=10;
$X=20;
$y=$x+$X;
echo $y;
?>
</body>
</html>
Output:
30
<! DOCTYPE html>
<html>
<body>
<?php
$x=10;
$x=20;
$y=$x+$x;
echo $y;
?>
</body>
</html>
Output:
40
Comments