-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtechnology-companies.php
133 lines (90 loc) · 2.6 KB
/
technology-companies.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
$companies = [
'Sun Microsystems' => [
'Vinod Khosla',
'Bill Joy',
'Andy Bechtolsheim',
'Scott McNealy'
],
'Silicon Graphics' => [
'Jim Clark',
'Ed McCracken'
],
'Cray' => [
'William Norris',
'Seymour Cray'
],
'NeXT' => [
'Steve Jobs',
'Avie Tevanian',
'Joanna Hoffman',
'Bud Tribble',
'Susan Kare'
],
'Acorn Computers' => [
'Steve Furber',
'Sophie Wilson',
'Hermann Hauser',
'Jim Mitchell'
],
'MIPS Technologies' => [
'Skip Stritter',
'John L. Hennessy'
],
'Commodore' => [
'Yash Terakura',
'Bob Russell',
'Bob Yannes',
'David A. Ziembicki',
'Jay Miner'
],
'Be Inc' => [
'Steve Sakoman',
'Jean-Louis Gassée'
]
];
echo "I am so pissed i just saved over all this work!\n";
// print companies
echo "\n\n\nhere is my array: \n";
foreach ($companies as $key => $value) {
echo $key . PHP_EOL;
}
//sort companies by name
echo "\n\n\nnow stuff is sorted by company name:\n";
ksort($companies);
foreach ($companies as $key => $value) {
echo $key . PHP_EOL;
}
// modify array to position last name first for lastname sorting
foreach ($companies as &$value) {
foreach ($value as &$name) {
$tempArray = explode(" ", $name);
array_unshift($tempArray, array_pop($tempArray));
$name = implode(" ", $tempArray);
}
}
// sort people by name
foreach ($companies as $key => &$value) {
asort($value);
}
// change array back to first name last name order for printing
foreach ($companies as &$value) {
foreach ($value as &$name) {
$tempArray = explode(" ", $name);
array_push($tempArray, array_shift($tempArray));
$name = implode(" ", $tempArray);
}
}
echo "\n\n\ncompany people are sorted alphabetically by lastname\n";
var_export($companies);
// sort companies biggest to smallest
echo "\n\n\nnow stuff is sorted by biggest to smallest company:\n";
arsort($companies);
foreach ($companies as $key => $value) {
echo $key . PHP_EOL;
}
foreach ($companies as $key => $people) {
shuffle($people);
$companies[$key] = $people;
}
print_r($companies);