-
Notifications
You must be signed in to change notification settings - Fork 12
/
functional.php
53 lines (45 loc) · 1.32 KB
/
functional.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
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
function User($name, $title) {
$user['name'] = $name;
$user['title'] = $title;
return $user;
}
function Developer ($name, $title, $skills) {
$user = User($name, $title);
if (!is_array($skills)) {
$skills = array($skills);
}
$user['skills'] = $skills;
return $user;
return $user;
}
function getSalutation($user) {
$salutation = $user['title'] . " " . $user['name'];
if (isset($user['skills'])) {
$salutation .= ", Developer";
}
return $salutation;
}
function getSkillsString($user) {
return implode(", ",$user['skills']);
}
$user = User("Jane Smith","Ms");
//we can't set anything to know how to display default
echo $user;
//we CAN var_dump, access directly or use another function
var_dump($user);
$user['name'] = 'Sue';
echo getSalutation($user);
echo "<br />";
$developer1 = Developer("Jane Smith", "Ms","PHP");
echo getSalutation($developer1);
echo "<br />";
echo getSkillsString($developer1);
echo "<br />";
$developer2 = Developer("Jane Smith", "Ms", array("JavasScript", "HTML", "CSS"));
$developer2['skills'][] = "PHP";
echo getSalutation($developer2);
echo "<br />";
echo getSkillsString($developer2);