-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
42 lines (38 loc) · 807 Bytes
/
functions.php
File metadata and controls
42 lines (38 loc) · 807 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
<?php
// step 2
function printArray($numbers)
{
$printArray ='';
$arrayLength = count($numbers);
for($i = 0; $i < $arrayLength; $i++)
{
$printArray .= "<p>$numbers[$i]</p>";
}
return $printArray;
}
// step 4
function largest($numbers)
{
$arrayLength = count($numbers);
$max = $numbers[0];
for($i = 1; $i < $arrayLength; $i++)
{
if($max < $numbers[$i])
{
$max = $numbers[$i];
}
}
return $max;
}
// step 5
function removeDups($numbers)
{
$sorted = array_values(array_unique($numbers, SORT_NUMERIC));
$arrayLength = count($sorted);
$printArray ='Array after removing duplicates ';
for($i = 0; $i < $arrayLength; $i++)
{
$printArray .= $sorted[$i] . " ";
}
return $printArray;
}