Comments, Variables, Constants and data types about PHP.

  • REVIEWS

-In the PHP code, a comment is a text that is not executed by the program. You can use the comments to explain the code you wrote. Single-line comments begin //:
<? Php
echo "<p> Hello! </p>";
// This is a single-line comment
echo "<p> I'm learning PHP! </p>";
echo "<p> This is my first program in PHP! </p>";
?>



Multi-line comments
-Multi-line comments are used for comments that are more than one line. A multi-line comment starts with / * and ends with * /.
<? Php
echo "<p> Hello! </p>";
/ *
This is a comment that
divided into
three lines
* /
echo "<p> I'm learning PHP! </p>";
echo "<p> This is my first php program! </p>";?>

This is a very good practice, adding comments to your code. This will help others understand your code or even you when you return it a moment later.

  • VARIABLES

-Varieties are used as "covers" in which we store information. A PHP variable starts with a dollar sign ($), which is followed by the variable name:

Emri_variables = $ value;

Rules for PHP variables:

- A variable name must start with a letter or _
- A variable name cannot start with a number.
- A variable name can contain alphanumeric letters and _ (A-z, 0-9, and _)
- Variable names are case-sensitive ($ name and $ NAME are two different variables)

For example:
<? Php
$ name = 'Jon';
$ age = 24;
echo $ name;
// Output 'Jon'
?>

In the example above, note that we do not tell PHP what type of data the variables are. PHP automatically converts variables to the appropriate data type, depending on their value. Unlike other programming languages, PHP does not have commands for declaring variables. This happens when I give a value to the variables.

  • CONSTANTS

-Constants are similar to variables except that they cannot be redefined after they have been given a certain value. Constants begin with letters or _. To create a constant, use the define () function as:

define (name, value, case-insensitive)

parameters:
name: Specifies the name of the constant;
value: Specifies the value of the constant;
case-insensitive: Specifies whether it will be case-sensitive or not. Previously the value is false; The following example creates a case-sensitive constant:
<? Php
define ("constant", "This is the constant value!");
echo constant;
// Output "This is the constant value!"
?>

The following example creates a non-case-sensitive constant:
<? Php
define ("constant", "This is the constant value!", true);
echo CONSTANT;
// Output "This is the constant value!"
?>

It is not necessary to use the dollar sign in front of constant names.

  • TYPES OF DATA

-Varieties can store different types of data. Types of data supported by PHP: String, Integer, Float, Boolean, Array, Object, NULL, Resource.

  • PHP String

-A string is a character sequence, like "I'm learning PHP!". A string can be inside single or even quotes.
<? Php
$ string1 = "I'm learning PHP!"; // Single cite
$ strin2 = "I'm learning PHP! '; // Single nails
?>

To join two strings we use the point union operator (.)
For example:
echo $ s1, $ s2

Post a Comment

0 Comments