Pemrograman Dasar PHP
sumber: w3schools
Basic Syntax
contoh 1
<?php
// PHP code goes here
?>
contoh 2
<!DOCTYPE html>
<html>
<body>
<h1>My first PHP page</h1>
<?php
echo "Hello World!";
?>
</body>
</html>
contoh 3
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
Comments
<?php
// This is a single-line comment
# This is also a single-line comment
?>
<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>
Variable
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
Data Types
Variabel bisa menyimpan data dengan type yang berbeda dan type data memiliki fungsi yang berbeda-beda.
PHP mendukung type data sebagai berikut:
- String
- Integer
- Float (floating point numbers - also called double)
- Boolean
- Array
- Object
- NULL
- Resource
Operators
https://www.w3schools.com/php/php_operators.asp
Percabangan
https://www.w3schools.com/php/php_looping.asp
Perulangan
https://www.w3schools.com/php/php_looping.asp