-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitemsAlgo.php
More file actions
40 lines (30 loc) · 1.04 KB
/
Copy pathitemsAlgo.php
File metadata and controls
40 lines (30 loc) · 1.04 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
<?php
class ArrangListAlgorithm
{
public function findItem(array $itemList, string $name)
{
$exist = false;
foreach ($itemList as $key => $item) {
if ($name === $item) {
$exist = $key;
}
}
return $exist;
}
public function arrangeItems(array $arrangedItems, array &$itemList)
{
foreach ($arrangedItems as $arranged) {
$arrangeNow = $this->findItem($itemList, $arranged);
if ($arrangeNow !== false) {
array_splice($itemList, $arrangeNow, 1);
}
}
}
}
$cars = ['Mercides', 'Honda', 'Daf', 'Toyota', 'Renault', 'Nissan']; // This array contains the unordered cars
$addedCars = ['Mercides', 'Honda', 'Daf']; //this array contains the cars that has been orderd;
$first = new ArrangListAlgorithm();
$first->arrangeItems($addedCars, $cars);
$unListedCars = implode(',', $cars);
echo $unListedCars."\n"." has not been listed\n";
echo "Here is the list of arranged cars\n".implode(' , ', $addedCars);