-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.php
More file actions
48 lines (37 loc) · 796 Bytes
/
testing.php
File metadata and controls
48 lines (37 loc) · 796 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
39
40
41
42
43
44
45
46
47
48
<?php
// function testing1($var){
// $i = "";
// $x = [];
// foreach ($var as $key => $value) {
// if ($i === "" || $i < $value){
// $i = $value;
// array_push($x,$value);
// }
// }
// return $i. ", ".$x[count($x)-2];
// }
// $asdf = [-65,5,-13,-23,-8,-1];
// echo testing1($asdf);
function lastString($string){
$arr = explode(" ", $string);
$new = [$arr[0]];
$y = 0;
$x = "";
foreach ($arr as $key => $value) {
if ($y > strlen($value)){
$x = $value;
}
$y = strlen($value);
}
return $x;
}
echo lastString("Gene is an amazing cook");
// function subStringNew($string){
// $arr = str_split($string);
// $newArr = [];
// foreach ($arr as $key1 => $value1) {
// foreach ($arr as $key2 => $value2) {
// array_push($newArr,$value2);
// }
// }
// }