Core PHP PHP

PHP Basic Syntax

PHP Basic Syntax

PHP starts and end tags

PHP starts with <?php and end with ?>
<?php
// Write PHP code here
?>

Default files extension for PHP is “.php”.

PHP files can contains HTML tags, and PHP code.

 

PHP print types

PHP can print in 3 types
1. “echo” to output the text
2. “print” its same as “echo”. Mostly we use “echo”.
3. “print_r” use for print array of php.

 

1. Example
<!DOCTYPE html>
<html>
<body>

<?php
echo “My first PHP project!”;
?>

</body>
</html>

2. Example
<!DOCTYPE html>
<html>
<body>

<?php
print “My first PHP project!”;
?>

</body>
</html>

3. Example
<!DOCTYPE html>
<html>
<body>

<?php
$id = [1, 2, 3, 4, 5]
print_r($id);
?>

</body>
</html>

Note: PHP end with a semicolon (;).

 

PHP Comments

PHP comment code is a line that is not read or executed as part of the program. It is purpose is to view, write not or mark for understand for coder.

Types of comments.
1. Single line comment.
2. Multi line comment.

Example of single line comment.
<!DOCTYPE html>
<html>
<body>

<?php
// Single line comment

# Single line comment

// You can also use comments to leave out parts of a code line
$x = 5 /* + 15 */ + 5;
echo $x;
?>

</body>
</html>
Example of multi line comment.
<!DOCTYPE html>
<html>
<body>

<?php
/*
Example of multiple
lines comment block
lines
*/

$x = 5 /* + 15 */ + 5;
echo $x;
?>

</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *