Professional Documents
Culture Documents
1. Buka XAMPP
2. Jalankan Apache
3. Ketikkan di web browser => localhost/psw2/namaFolder/namaFile.php
Latihan!
1. Hello World!
<?php
echo "Hello, World!";
?>
Perbaiki potongan kode berikut!
<?php
echo "Hello, World!"
ECHO "Hello, World!"
ecHO "Hello, World!"
echo 'Hello, World!'
echo ('Hello, World!')
echo Hello!
?>
3. Operators
<?php
// Sum up the variables x and y and
// put the result in the sum variable.
$x = 19;
$y = 25;
$sum = NULL;
echo "The sum of $x and $y is $sum."
?>
Perbaiki potongan kode berikut!
<?php
$x = 1;
$y = 3;
$sum = $x + $y;
echo $Sum;
?>
5. Constant
<?php
define("PI", 3.1415927);
$radius = 7.0;
echo PI * ($radius * $radius);
?>
if($name == 'Wiro'){
echo('Your weapon is the 2-1-2 axe.');
} else if($name == 'Wolverine'){
echo ('Your weapon is the cat-paw.');
} else{
echo ('You have no weapon.');
}
?>
7. Switch Case
<?php
$name = 'Wiro';
switch($name){
case 'Wiro':
echo('Your weapon is the 2-1-2 axe.');
break;
case 'Wolverine':
echo ('Your weapon is the cat-paw.');
break;
defalut:
echo ('You have no weapon.');
break;
}
?>
8. Foreach Looop
<?php
$arrName = array(
'Wiro Sableng', 'Jaka Sembung', 'Saras 008',
'Milkyman', 'Ranger Merah', 'Pikachu'
);
?>
<html>
<head><title>Arrays</title></head>
<body>
<h2>My Super hero</h2>
<ul>
<?php
foreach($arrName as $name){
echo('<li>' .$name.'</li>');
}
?>
</ul>
</body>
</html>
- Selamat berlatih -