PHP (Hypertext Preprocessor) adalah bahasa pemrograman server-side yang digunakan untuk mengembangkan aplikasi web dinamis. Berikut adalah beberapa konsep dasar dalam PHP:
$x = 5;
$y = "Hello";
$z = true;
$name = "John";
echo "Hello, $name!";
if ($x > 0) {
echo "Positif";
} else {
echo "Negatif";
}
for ($i = 0; $i < 5; $i++) {
echo $i;
}
function greet($name) {
return "Hello, " . $name . "!";
}
$greeting = greet("World");
$numbers = array(1, 2, 3, 4, 5);
$fruits = ["Apple", "Banana", "Orange"];
<form action="submit.php" method="post">
<label for="name">Nama:</label>
<input type="text" id="name"
name="name"><br>
<input type="submit" value="Submit">
</form>
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
session_start();
$_SESSION['user'] = "John";
echo "Welcome, " . $_SESSION['user'];