PHP Fundamentals

Learn PHP programming from scratch, including variables, functions, arrays, and object-oriented programming.

beginner Backend Development 6 hours

Chapter 3: PHP Syntax and Basics

Chapter 3 of 15

Chapter 3: PHP Syntax and Basics

3.1 Basic PHP Syntax

PHP code is embedded in HTML using special tags.

<?php
// PHP code goes here
echo "Hello, World!";
?>

3.2 PHP Tags

PHP supports different tag styles.

<?php ?>  // Standard tags (recommended)
<? ?>     // Short tags (requires configuration)
<?= ?>    // Short echo tags

3.3 Comments

Comments document your code and are ignored by PHP.

// Single-line comment
# Single-line comment (alternative)

/* Multi-line
   comment */

3.4 Outputting Data

Display data using echo, print, or print_r.

echo "Hello, World!";
print "Hello, World!";
print_r($array);  // For arrays
var_dump($variable);  // Detailed output