Loading...

Breif information about PHP syntax

breif-information-about-php-syntax

Breif information about PHP syntax

  • study365days.in

PHP (Hypertext Preprocessor) is a widely used server-side scripting language for web development. It is embedded within HTML code to create dynamic web pages. Here's an overview of the basic syntax and key concepts in PHP:

01. Tags: PHP code is enclosed in <!--?php ?-->tags within an HTML document. For example:

<?php // PHP code here ?>

02. Comments: PHP supports single-line comments (//) and multi-line comments (/* ... */) for code documentation.

<?php
 // This is a single-line comment.
 /* This is a line one for multi-line comment.
 This is a line two for multi-line comment.
 This is a line three for multi-line comment. */
?>

03. Variables: Variables in PHP start with the $ symbol followed by the variable name. Variable names are case-sensitive and can contain letters, numbers, and underscores. They must start with a letter or underscore.

<?php
 $name = "John";
 $age = 30;
?>

04. Data Types: PHP supports various data types, including integers, floats, strings, booleans, arrays, and objects. The data type of a variable is dynamically determined based on its value.

05. Constants: Constants are defined using the define() function and are case-sensitive by default. They cannot be changed once defined.

<?php define("PI", 3.14159); ?>

06. Operators: PHP includes a variety of operators for performing operations on variables and values, such as arithmetic, comparison, logical, and assignment operators.

<?php
 $sum = $a + $b;
 $is_equal = ($a == $b);
?>