<?php $cities = json_decode(add_headers_to_json('cities.csv')); ?> <h1>States</h1> <?php $states = []; foreach ($cities as $city) { $states[] = $city->state; } $unique_states = array_unique($states); foreach ($unique_states as $state) { echo '<a href="/flight_challenge/v1/states/' . $state . '/cities/">' . $state . '</a><br>'; }
function visited_cities($visitfile, $cityfile, $user_id) { $visits = json_decode(add_headers_to_json($visitfile)); $visited_cities = array(); foreach ($visits as $visit) { $visit_user_id = $visit->user_id; if ($visit_user_id == $user_id) { $visited_city_id = $visit->city_id; $visited_city = find_city_by_id($cityfile, $visited_city_id); $visited_cities[] = $visited_city; } } if (count($visited_cities) > 0) { echo '<h3>Your Visited Cities:</h3>'; foreach ($visited_cities as $visited_city) { echo $visited_city->name . ", " . $visited_city->state . "<br>"; } return $visited_cities; } else { echo 'It looks like you haven\'t visited any cities yet!'; } }