Variable Local
- $var
- $VAR
4R- _v4r
-var
Variable yang digunakan untuk menangkap data :
- $_GET['namavar']
- $_POST['namavar']
- $_REQUEST['namavar']
- $_SESSION['namavar'] → variable server
- $_COOKIE['namavar'] → variable client
Percabangan
-- IF ELSE
if (syarat)
{ pernyataan }
{ pernyataan }
else if (syarat)
{ pernyataan }
{ pernyataan }
else
{ pernyataan }
{ pernyataan }
-- SWITCH
switch (var)
switch (var)
{ case syarat 1 :
pernyataan;
break;
case syarat 2 :
pernyataan;
break;
case syarat ....
...
break;
default :
pernyataan;
break; }
Perulangan
-- FOR
for( $i = 1 ; $i <= 10 ; i++ )
{ echo "Perulangan ke- ".$i;
echo "<br/>"; }
-- WHILE
$i = 1;
while ( $i <= 10 )
{ echo "Perulangan ke- ".$i;
echo "<br/>";
$i++; }
-- DO WHILE
$i=1;
do { echo "Perulangan ke- ".$i;
echo "<br/>";
$i++; }
while ( $i <= 10 )
-- FOREACH (Perulangan Array : var yang berisi kumpulan data)
$var['array1'] = 1;
$var['array2'] = 2;
foreach ($var as $V)
{ echo "Perulangan ke- ".$V;
echo "<br/>"; }
for( $i = 1 ; $i <= 10 ; i++ )
{ echo "Perulangan ke- ".$i;
echo "<br/>"; }
-- WHILE
$i = 1;
while ( $i <= 10 )
{ echo "Perulangan ke- ".$i;
echo "<br/>";
$i++; }
-- DO WHILE
$i=1;
do { echo "Perulangan ke- ".$i;
echo "<br/>";
$i++; }
while ( $i <= 10 )
-- FOREACH (Perulangan Array : var yang berisi kumpulan data)
$var['array1'] = 1;
$var['array2'] = 2;
foreach ($var as $V)
{ echo "Perulangan ke- ".$V;
echo "<br/>"; }
Variable untuk menyimpan data sementara di :
- Server = SESSION
- Client (browser) = COOKIES
Cookie ← $_COOKIE ['namavar'] = 'data';
set cookie ('namavar' ,
"data");
Contoh :
<?php
session_start();
if ( $_SESSION ['id'] == '1' )
{ echo 'Anda sudah login'; }
else if ( $_POST ['id'] == '1' )
{ echo '<a href =
"namafile.php"> klik disini </a>';
$_SESSION['id'] = $_POST ['id']; }
else
{ echo '<form method = "POST"
action= " ">
<input type = "text" name = "id"/>
<input type = "submit name = "submit" value =
"submit"/>
</form>'; }
?>
No comments:
Post a Comment