-
Notifications
You must be signed in to change notification settings - Fork 0
/
task1.php
80 lines (65 loc) · 2.01 KB
/
task1.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
<!DOCTYPE html>
<html>
<body>
<h1>Task 1</h1>
<?php
//Task 1(a)
function boolToText($boolValue, $format = 1) {
//use a switch for the format, and nested ifs for the values
switch ($format) {
case 1:
if($boolValue == TRUE) {
return "True";
} else {
return "False";
}
break;
case 2:
if($boolValue == TRUE) {
return "Yes";
} else {
return "No";
}
break;
case 3:
if($boolValue == TRUE) {
return "Positive";
} else {
return "Negative";
}
break;
default:
if($boolValue == TRUE) {
return "1";
} else {
return "0";
}
break;
}
}
?>
<h2>Task 1 (a) : </h2>
<p>boolToText(0); Result = <?php echo boolToText(0); ?></p>
<p>boolToText(1, 2); Result = <?php echo boolToText(1, 2); ?></p>
<p>boolToText(0, 3); Result = <?php echo boolToText(0, 3); ?></p>
<p>boolToText(1, 5); Result = <?php echo boolToText(1, 5); ?></p>
<br>
<?php
//Task 1 (b)
function checkNumerals(){
$numerals = 0;
$params = func_get_args();
foreach($params as $arg){
if(is_numeric($arg))
$numerals++;
}
echo "Total number of arguments: ".func_num_args().", total number of numerals in these arguments: $numerals";
}
?>
<h2>Task 1 (b) :</h2>
<p>checkNumerals("Thando", 23, "Busi", 40);</p>
<p><?php checkNumerals("Thando", 23, "Busi", 40); ?></p>
<p>checkNumerals("Mutsa");</p>
<p><?php checkNumerals("Mutsa"); ?></p>
</body>
</html>