Category: PHP Basics

PHP switch case after default works normally

When you put the a case block after the default block the switch will work normally and fallback to the default only after testing all cases.The documentation doesn’t specify this directly, but there is a note with an example.Another thing worth mentioning is that switch … Read more »

Variables

Variables are preceded in PHP by a dollar sign $ and the rules for naming are: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*   or in plain english names of variables can begin with letters or underscores and then you can put other numbers letters and underscores. Letters here can include extended ascii characters from … Read more »

Operators list

Arithmetic OperatorsExampleNameResult–$aNegationOpposite of $a.$a + $bAdditionSum of $a and $b.$a – $bSubtractionDifference of $a and $b.$a * $bMultiplicationProduct of $a and $b.$a / $bDivisionQuotient of $a and $b.$a % $bModulusRemainder of $a divided by $b.Assignment Operators<?php $a = 5; ?><?php $a = ($b = 2) + 5; // $a = 7 ?><?php $a = 2; $a += 3; // sets $a … Read more »

Syntax

PHP tagsPHP code must be put between some special characters<?php ?><? ?> // with short_open_tag enabled or php with option --enable-short-tags<script language="php"> </script> // old style<% %> // ASP style asp_tags enabledOther formats<?php echo 'message'; ?> // this are equivalents<?= 'message'; ?> // if short_open_tag … Read more »