php
được code trong thẻ <?php ?>
file mở rộng .php
Câu lệnh php kết thúc bằng dấu chấm phẩy ;
keyword trong php không phân biệt hoa thường(Tuy nhiên thì biến vẫn phân biệt)
https://viblo.asia/p/coding-convention-doi-voi-mot-project-php-ORNZqNPrl0n
<?php
// Đây là comment 1 dòng
# Đây cũng là comment 1 dòng
/* Đây là comment
* Nhiều dòng
*
* */
?>
Trong php biến được khai báo bắt đầu bằng $
Có 3 phạm vi biến
- local
- global
- static
PHP hỗ trợ kiểu:
- string
- interger
- float
- boolean
- array
- object
- null
- resource
<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>
<?php
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this condition is true;
} else {
code to be executed if all conditions are false;
}
?>
<?php
switch (n) {
case label1:
code to be executed if n=label1;
break;
case label2:
code to be executed if n=label2;
break;
case label3:
code to be executed if n=label3;
break;
...
default:
code to be executed if n is different from all labels;
}
?>
<?php
while (condition is true) {
code to be executed;
}
?>
for (init counter; test counter; increment counter) {
code to be executed for each iteration;
}
<?php
foreach ($array as $value) {
code to be executed;
}
?>
<?php
function functionName() {
code to be executed;
}
?>