-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforeach_states.php
131 lines (110 loc) · 2.79 KB
/
foreach_states.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
<?php
$states = [
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
'AR' => 'Arkansas',
'CA' => 'California',
'CO' => 'Colorado',
'CT' => 'Connecticut',
'DE' => 'Delaware',
'DC' => 'District of Columbia',
'FL' => 'Florida',
'GA' => 'Georgia',
'HI' => 'Hawaii',
'ID' => 'Idaho',
'IL' => 'Illinois',
'IN' => 'Indiana',
'IA' => 'Iowa',
'KS' => 'Kansas',
'KY' => 'Kentucky',
'LA' => 'Louisiana',
'ME' => 'Maine',
'MD' => 'Maryland',
'MA' => 'Massachusetts',
'MI' => 'Michigan',
'MN' => 'Minnesota',
'MS' => 'Mississippi',
'MO' => 'Missouri',
'MT' => 'Montana',
'NE' => 'Nebraska',
'NV' => 'Nevada',
'NH' => 'New Hampshire',
'NJ' => 'New Jersey',
'NM' => 'New Mexico',
'NY' => 'New York',
'NC' => 'North Carolina',
'ND' => 'North Dakota',
'OH' => 'Ohio',
'OK' => 'Oklahoma',
'OR' => 'Oregon',
'PA' => 'Pennsylvania',
'PR' => 'Puerto Rico',
'RI' => 'Rhode Island',
'SC' => 'South Carolina',
'SD' => 'South Dakota',
'TN' => 'Tennessee',
'TX' => 'Texas',
'VI' => 'US Virgin Islands',
'UT' => 'Utah',
'VT' => 'Vermont',
'VA' => 'Virginia',
'WA' => 'Washington',
'WV' => 'West Virginia',
'WI' => 'Wisconsin',
'WY' => 'Wyoming'
];
foreach ($states as $state) {
if (strpos($state, 'x')) {
fwrite(STDOUT, $state . PHP_EOL);
}
}
fwrite(STDOUT, PHP_EOL);
foreach ($states as $state) {
if (!strpos($state, 'a')) {
fwrite(STDOUT, $state . PHP_EOL);
}
}
fwrite(STDOUT, PHP_EOL);
$vowels = ['A', 'E', 'I', 'O', 'U'];
foreach ($states as $abbr => $state) {
if (in_array(substr($state, 0, 1), $vowels)) {
fwrite(STDOUT, "$abbr, $state" . PHP_EOL);
}
}
fwrite(STDOUT, PHP_EOL);
$statesStartingAndEndingWithVowels = [];
foreach ($states as $state) {
if (in_array(substr($state, 0, 1), $vowels) and in_array(strtoupper(substr($state, -1)), $vowels)) {
$statesStartingAndEndingWithVowels[] = $state;
}
}
fwrite(STDOUT, 'These are the states starting and ending with vowels:' . PHP_EOL);
foreach ($statesStartingAndEndingWithVowels as $state) {
fwrite(STDOUT, $state . PHP_EOL);
}
fwrite(STDOUT, PHP_EOL);
$statesWithMoreThanOneWordNames = [];
foreach ($states as $state) {
if (strpos($state, ' ')) {
$statesWithMoreThanOneWordNames[] = $state;
}
}
fwrite(STDOUT, 'These are the states with more than one word in their name:' . PHP_EOL);
foreach ($statesWithMoreThanOneWordNames as $state) {
fwrite(STDOUT, $state . PHP_EOL);
}
fwrite(STDOUT, PHP_EOL);
$arrayOfCardinalStates = [];
$cardinalDirections = ['North', 'South', 'East', 'West'];
foreach ($states as $state) {
foreach ($cardinalDirections as $direction) {
if (strpos($state, $direction) !== false) {
$arrayOfCardinalStates[] = $state;
}
}
}
fwrite(STDOUT, 'These are states with north, south, east, or west in their name:' . PHP_EOL);
foreach ($arrayOfCardinalStates as $state) {
fwrite(STDOUT, $state . PHP_EOL);
}