-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbackPhp.php
40 lines (32 loc) · 960 Bytes
/
callbackPhp.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
<!DOCTYPE html>
<html>
<head>
<title>Php Practice</title>
</head>
<body>
<h1>My First PHP page</h1>
<?php
function exclaim($str) {
return $str . "!";
}
function ask($str) {
return $str . "?";
}
function printFormatted($str, $format) {
echo "<p>". $format($str) ."</p>";
}
printFormatted("Hi", "exclaim");
printFormatted("How are you", "ask");
echo "<br>";
function myCallback($item) {
return strlen($item);
}
$strings = ["apple", "orange", "banana", "coconut"];
$lengths = array_map("myCallback", $strings);
$lengthAno = array_map(function ($item) { return strlen($item); }, $strings);
print_r($lengthAno);
echo "<br>";
print_r($lengths);
?>
</body>
</html>