-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
109 lines (90 loc) · 2.23 KB
/
Copy pathindex.php
File metadata and controls
109 lines (90 loc) · 2.23 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Palindrome</h1>
<?php
$input = "abcba";
function Palindrome($input){
$reversed="";
$splited =str_split($input);
$t_lengt=count($splited);
for ($y=$t_lengt-1; $y >-1 ; $y--) {
$reversed.=$splited[$y];
}
if ($input== $reversed){
echo "Palindrome";
}
else{
echo "Not a Palindrome";
}
}
Palindrome($input);
?>
<h1>Second</h1>
<?php
function done($main){
$rev = strrev($main);
$counted =strlen($main);
$half = round($counted /2);
$orginal= substr($rev,$half);
$first = strrev($orginal);
$last = substr($main,$half);
if ($first == $last) {
echo "Matched";
}else{
echo "Not matched";
}
}
done('abzab');
?>
<h1>Third</h1>
<?php
function third($arr){
$counted = count($arr);
$new =[];
//final result array
$result_array=[];
for($i=0;$i<$counted;$i++){
for($j=$i+1;$j<$counted;$j++){
array_push($new, $arr[$i] + $arr[$j]);
}
}
//print_r($new);
echo 'The max sum of every Two Number is number is : '.max($new);
$final_array=[];
?>
<br>
<?php
//seperating the digits but putting each result into diffrent sub array
foreach ($new as $value) {
$int_length =strlen($value);
$fin_length = $int_length-1;
if ($int_length > 1){
array_push($final_array,str_split($value));
}else{
array_push($result_array,$value);
}
}
//print_r($final_array);
?>
<br>
<?php
foreach($final_array as $value) {
$tval=0;
foreach($value as $val) {
$tval+=$val;
}
array_push($result_array, $tval);
}
echo 'The max sum of all previous result is : '.max($result_array);
}
third(array(8, 10, 12, 14,9999999,99999,99999999999));
?>
</body>
</html>