Sie sind auf Seite 1von 17

A.

BASIC I/O
<?php echo "whatsup"; ?> Hasil: whatsup <?php echo 123; ?> Hasil: 123 <?php echo Hello World! <br> New line; ?> Hasil: Hello World! New line <?php $sometext = harry poter; echo $sometext; ?> Hasil: harry poter <?php $sometext = harry poter; $somenumber = 32;

echo $sometext.$somenumber; ?> Hasil: harry poter32

B. BASIC MATH FUNCTION


<?php $somenumber = 34+34; echo $somenumber; ?> Hasil: 68 <?php $somenumber = 34; $someelse = 34; echo $somenumber + $someelse; ?> Hasil: 68 {fungsi yg dipakai ada +, -, /, *,%(modulus)} bila ada + dan / maka akan didahulukan / gunakan tanda kurung untuk memisahkan fungsi aritmatiknya

C. VARIABEL

<?php $name = Alex; $age = 19;

echo My name is $name and my age is $age.; ?> Hasil: My name is Alex and my age is 19.

D. IF ELSE STATEMENT
<?php $first = 10; $second = 20; $third = 30; if ($first<$second) {echo this is true;} else {echo this is false;} ?> Hasil: this is true Fungsi yang dapat dipakai : <, >, <=,>=,==,!=

E. IF ELSEIF IF
<?php $var = steve; if ($var == steve) echo hey stevo; elseif ($var == brian)

echo hey there bri; else echo who are you; ?> Hasil: hey stevo <?php $var = brian; if ($var == steve) echo hey stevo; elseif ($var == brian) echo hey there bri; else echo who are you; ?> Hasil: hey there bri

F. SWITCH STATEMENT
<?php $country = USA; switch ($country) { case USA: echo your in USA; break;

case japan: echo your in japan; break; default: echo you messed up; break; } ?> Hasil: your in USA

G. WHILE LOOP
<?php $num = 1; While ($num <= 5) { echo $num.</br>; $num++; } ?> Hasil: 1 2 3 4 5

H. DO LOOP
<?php $num = 1; do { $num++; echo $num.</br>; } while($num<10); ?> Hasil: 2 3 : : 10

I. FOR LOOP
<?php for ($num=1; $num<=5; $num++) { echo hello world. </br>; } ?> Hasil:

hello world hello world hello world hello world hello world

J. ARRAY
<?php $people = array (tom,jake,tony); $people[0]=tom; $people[1]=jake; $people[2]=tony; echo $people[2]; ?> Hasil: tony

K. ASSOCIATIVE ARRAY
<?php $actions = array (fingers=>hand,toes=>foot,teeth=>mouth); echo $actions[fingers]; ?> Hasil: hand

L. ADDING AND MODIFYING ELEMENT IN AN ARRAY


<?php $name[0]=tom; $name[1]=greg; $name[2]=mike; echo $name[0]; $name[0]=bucky; echo $name[0]; ?> Hasil: tombucky

M. ARRAY WITH LOOP


<?php $test = array (tom,tony,greg,mike); for ($x=0; $x=sizeof($test; $x++) echo $test[$] ?> Hasil: tomtonygregmike

N. FOR EACH ARRAY LOOPS


<?php $test = array (one,two,three); foreach ($test as $x)

echo $x ?> Hasil: onetwothree

O. FUNCTIONS
<?php function testfun() { echo easy hoss! } echo take it ; testfun(); echo </br>.i said take it; testfun(); ?> Hasil: take it easy hoss! i said take it easy hoss!

P. PARAMETER IN FUNCTIONS
<?php function somefun($sub) { echo $sub.hoss </br>!; }

somefun(take it easy ); somefun(i said take it easy); ?> Hasil: take it easy hoss! i said take it easy hoss!

Q. RETURN VALUES
<?php function add($a,$b) { $total = $a + $b; return $total; } echo add(8,9) ?> Hasil: 17

R. BEGINNING FORMS

Buat 2 buah file bernama welcome.php dan testerpage.php

welcome.php ==========

<html> <body>

<form action=testerpage.php method=post> Name: <input type=text name=name/> <input type=submit value=Kirim/> </form> </body> </html>

testerpage.php ===========
<html> <body>

<?php echo $_POST[name]; ?>

</body> </html>

Hasil:

S. DATE FUNCTION

<?php echo date(m/d/Y); ?> Hasil: 17/20/2008 {berdasarkan tanggal komputer saat file ini dibuka} {gunakan / atau -}

T. INCLUDE FUNCTION Buat 2 buah file bernama welcome.php dan testerpage.php welcome.php ==========
<?php

echo easy hoss; ?>

testerpage.php ==========
<html> <body> <?php include (welcome.php);?> <h1> Welcome People </h1> <p> Hey now all star</p> </body> </html>

Hasil:

U. GET VARIABEL
<?php echo $_GET(myname); ?>

Hasil:

<html> <form action=get.php method=GET> <input type=textname=myname><br> <input type=submit value=Click here> </form> </html> Hasil:

<html> <form action=get.php method=GET> <input type=textname=myname><br> <input type=submit value=Click here> </form> </html> <?php $name = $_GET[myname]; if($name) echo Hello, $name.;

?> Hasil:

V. COMPARISON OPERATORS
<?php if (1 == 1) echo True; else echo False; ?> Hasil: True <?php $password = abc if ($password = def) { echo ACCESS GRANTED; }

else { echo ACCESS DENIED; } ?> Hasil: ACCESS DENIED

W. Creating database

X.

Das könnte Ihnen auch gefallen