-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsoal1.php
77 lines (66 loc) · 1.49 KB
/
soal1.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
// membuat class biodata
class Biodata{
// menyimpan data dalam array
public $data = [];
// fungsi nama
public function nama($nama)
{
$this->data['name'] = $nama;
return $this;
}
// fungsi alamat
public function alamat($alamat)
{
$this->data['address'] = $alamat;
return $this;
}
// fungsi hobi
public function hobi($hobi = array())
{
$this->data['hobbies'] = $hobi;
return $this;
}
// fungsi menikah
public function menikah($menikah)
{
$this->data['is_married'] = $menikah;
return $this;
}
// fungsi sekolah
public function sekolah($sekolah = array())
{
$this->data['school'] = $sekolah;
return $this;
}
// fungsi kemampuan
public function kemampuan($kemampuan = array())
{
$this->data['skills'] = $kemampuan;
return $this;
}
// fungsi konvert ke json
public function konjson(){
return json_encode($this->data, JSON_PRETTY_PRINT);
}
}
$biodata = new Biodata();
$nama = "Hamdan Ibrahim";
$alamat = "Ds.Jadimulya GG.Mushollah No.88 RT.03 RW.01 Kab.Cirebon Kec.Gunung Jati Prov.Jawa Barat";
$hobi = ['Sepedah','Bulu Tangkis','Membaca Berita','Ngoding'];
$sekolah = [
"highSchool" => "SMK Negeri 1 Kedawung",
"university" => ""
];
$kemampuan = [
"Web" => ['HTML','CSS','PHP'],
"Olahraga" => ['Sepedah']
];
print_r($biodata->nama($nama)
->alamat($alamat)
->hobi($hobi)
->menikah(false)
->sekolah($sekolah)
->kemampuan($kemampuan)
->konjson()
);