-
Notifications
You must be signed in to change notification settings - Fork 0
/
Birdcode.php
62 lines (49 loc) · 1.55 KB
/
Birdcode.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
<?php
class Birdcode{
public static function createBirdCode(array $_params)
{
foreach($_params as $value){
$value = explode(' ', $value);
// var_dump($value);
Birdcode::checkValueLength($value);
}
}
/**
* check the lenth value and give a response in eachcase
*/
public static function checkValueLength($_paramsValues)
{
$lenthValue = count($_paramsValues);
if($lenthValue == 1){
foreach($_paramsValues as $birdName){
$results[] = strtoupper($birdName[0].$birdName[1].$birdName[2].$birdName[3]);
}
var_dump($results);
return $results;
}
2
if($lenthValue == 2){
foreach($_paramsValues as $birdName){
// var_dump($birdName[0].$birdName[1]);
$results[] = strtoupper($birdName[0].$birdName[1]);
}
var_dump($results);
return $results;
}
if($lenthValue == 3){
foreach($_paramsValues as $key => $birdName){
if( $key == 2){
echo $key;
// var_dump($birdName[0]);
$results[] = strtoupper($birdName[0].$birdName[1]);
}else{
$results[] = strtoupper($birdName[0]);
}
}
var_dump($results);
return $results;
}
}
}
$birds1 = ["Bobolink", "American White Pelican"];
Birdcode::createBirdCode($birds1);