Contoh array :

membuat array

ARRAY WARNA

<?php

$warna = array ("merah", "kuning", "hijau");

echo "isi dari array adalah:
“;
echo “warna [0] = $warna[0]
“;
echo “warna [1] = $warna[1]
“;
echo “warna [2] = $warna[2]
“;

?>

Contoh array asosiatif :

membuat array

ARRAY ASOSIATIF

<?php

$kode [jakarta] = "021";
$kode [bandung] = "022";
$kode [tanjungpinang] = "0771";

echo "Daftar Kode Telepon Kota :
“;
echo “kode jakarta = $kode[jakarta]
“;
echo “kode bandung = $kode[bandung]
“;
echo “kode tanjungpinang = $kode[tanjungpinang]
“;

?>

Contoh penggunaan operator-operator pada php

operator assigment

<?php
$x = 30.5;
$y = 15;
$z = $x-$y;
echo $z–;

$p = "1.2";
$q = 5.7;
$s = $x+$p;
echo "
nilai p = $p, q = $q, s = $s
“;

$a = “Hallo…..”;
$b = “Apa Kabar…”;
$c = $a.$b;
$d = “Selamat Pagi….”;
echo $c.$d;
echo “
“;

$e=(float)3.5+$q;
echo “hasilnya adalah = $e
“;

$x–;
$y+=5;
$w=$x+$y;
echo “
nilai x = $x, y = $y
“;
echo ” hasilnya adalah = $w
“;

$x+= 1;
$y-= 4;
$t = $x+$y;
echo ” hasilnya adalah = $t
“;

?>