-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphpChallenge.php
102 lines (55 loc) · 1.17 KB
/
phpChallenge.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
$test = [1,1,3,3,4,4,5,5,7,7,8];
$prev = $test[0];
$post = $test[0];
for ($i=0; $i < count($test) ; $i++) {
if ($i == count($test) - 1) {
$prev = $test[$i];
} else {
$prev = $test[($i+1)];
}
if ($i==0) {
$post = $test[0];
} else {
$post = $test[($i-1)];
}
if ( $test[$i] != $prev && $test[$i] != $post) {
echo "1. this is the value " . $test[$i] . PHP_EOL;
}
if ($i==0 && $test[$i]!=$prev) {
echo "1. this is the value " . $test[$i] . PHP_EOL;
}
if ($i== (count($test)-1) && $test[$i]!=$post) {
echo "1. this is the value " . $test[$i] . PHP_EOL;
}
}
function palindrome($numb) {
$numb = strval($numb);
$rev_numb = strrev($numb);
if ($numb == $rev_numb) {
echo "2. this is a palindrome " . $numb . PHP_EOL;
} else {
echo "2. NOT a palindrome " . $numb . PHP_EOL;
}
}
palindrome(78987);
palindrome(5890985);
palindrome(12312);
palindrome(9000009000000009);
function cmp_function($arr) {
$a
$b
$c
for ($i=0; $i < count($arr); $i++) {
// even number
if ($i%2 == 0) {
} else {
}
}
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
}
usort($arr, cmp_function)