-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0505.php
More file actions
38 lines (32 loc) · 1014 Bytes
/
0505.php
File metadata and controls
38 lines (32 loc) · 1014 Bytes
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
<?php
declare (strict_types = 1);
echo '<pre>';
// echo 'I am going to start';
function customCode(string $str)
{
// $processedStr = str_split(strtolower($str));
// // print_r($processedStr);
// $myAry = range('a', 'z');
// // print_r($myAry);
// $result = array_map(function ($a) {return array_search($a, range('a', 'z'));}, $processedStr);
// // print_r($result);
// $result = array_filter($result);
// $finalResult = array_map(
// function ($a) {
// return $a != '' ? $a + 1 : '';
// }, $result
// );
// // print_r($finalResult);
// return implode(" ", $finalResult);
// // return 'This is output';
$abc = array_flip(range('a', 'z'));
$string = [];
foreach (str_split(strtolower($str)) as $letter) {
if (isset($abc[$letter])) {
$string[] = $abc[$letter] + 1;
}
}
return implode(' ', $string);
// return 'test';
}
echo customCode("The sunset sets at twelve o' clock.");