Chose Language:
comments
Author: Admin/Publisher |finished | checked

PHP Syntax

First, you need to create a .php file for testing. In this article, the different elements that are part of PHP syntax will be shown and explained.

A PHP script can be placed anywhere and is composed as follows. It starts with <?php and ends with ?> depending on whether it is embedded in HTML or not. If the code is not mixed with HTML in the .php file, you can leave it without the ?>.

<?php
//el código php va aquí
?>

PHP Comments

As you can see in the previous example, I used //, which means it’s a single-line comment. This can also be done using #. Comments in PHP or any language are parts of the code that are not executed or read.

Although you might not see the usefulness of it right now, I have to tell you that comments help you remember what a function does or understand what a piece of code is doing.

However you use them, don’t overuse comments, but also don’t leave your code without comments. A comment can be beneficial, but it can also make the code harder for another programmer to read. If you comment, do it clearly and concisely.

All that is at the right of # or // will be treated as a comment

<?php
   #soy un comentario de una línea
   //soy otro comentario de una línea
?>

You may make multilinear comment with /* top open the comment area and */ to close it.

<?php
/* este es un comentario de
mas de una linea*/
?>

PHP and case-sensitive

In PHP, keywords such as (if, else, while, echo, class, function, etc.) are not case-sensitive, but variables are.

<?php
   /*En los siguientes 3 casos imprimirá esto es un tutorial de php*/
   echo "esto es un tutorial de php";
   Echo "esto es un tutorial de php";
   ECho "esto es un tutorial de php";
?>

Variables are declared with the $ sign in front, but we will see more about them later. You just need to know that $a is not the same as $A. Both $a and $A are two different variables.

<?php
   $A; //declarando una variable $A
   $a; // declarando una variable $a
?>

All statements in PHP end with a semicolon ;

referencias:
sintaxis básica en php.net

Category: en-php
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category

Comments