-
Notifications
You must be signed in to change notification settings - Fork 0
/
perulangan.php
42 lines (35 loc) · 957 Bytes
/
perulangan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class MyClass //membuat sebuah class
{
public $var1 = 'value 1'; //deklarasi propertis
public $var_kedua = 'value 2';
public $var_three = 'value 3';
protected $protected = 'protected var';
private $private = 'private var';
function Ulang() { //membuat sebuah method
echo "MyClass::Ulang :<br/>";
foreach($this as $key => $value) { //menampilkan semua data array
print "$key => $value<br/>";
}
}
function Buat_method(){
echo "Test Membuat Method Baru";
}
function Gabung_var(){
$var1='Aku '; $var_kedua='Lapar ';
print "$var1"."$var_kedua";
}
}
$class = new MyClass(); //membuat object
//mencetak semua variable di class MyClass
foreach($class as $key => $g) {
print "$key => $g <br/>";
}
echo "<br/>";
//memanggil function ulang()
$class->Ulang();
echo "<br/><br/>";
$class->Buat_method();
echo "<br/><br/>";
$class->Gabung_var();
?>