<?php
$locations = Array(
Array
(
'id' => 14,
'post_id' => 319,
'location' => 'Atlanta, GA',
'address' => '161 Racetrack Rd., McDonough',
'city' => 'Atlanta',
'state' => 'Georgia',
'state_code' =>'GA',
'country' => 'USA',
'zipcode' => 30253,
'service_zipcode' => '',
'phone' => '',
'fax' => '',
'email' => '',
'facebook' => '',
'twitter' => '',
'linkedin' => '',
'gplus' => '',
'latitude' => '',
'longitude' => '',
'url' => '',
'created_at' => '2019-04-22 07:22:55',
'updated_at' => '2019-04-22 07:26:31',
),
Array
(
'id' => 16,
'post_id' => 321,
'location' => 'Augusta, Georigia',
'address' => '1446 Harper Street',
'city' => 'Augusta',
'state' => 'Georigia',
'state_code' => 'GA',
'country' => 'USA',
'zipcode' => '',
'service_zipcode' => '',
'phone' => '',
'fax' => '',
'email' => '',
'facebook' => '',
'twitter' => '',
'linkedin' => '',
'gplus' => '',
'latitude' => '',
'longitude' => '',
'url' => '',
'created_at' => '2019-04-22 07:29:33',
'updated_at' => '2019-04-22 07:32:25',
),
Array
(
'id' => 16,
'post_id' => 321,
'location' => 'Augusta, Georigia',
'address' => '1446 Harper Street',
'city' => 'Huston',
'state' => 'Texas',
'state_code' => 'GA',
'country' => 'USA',
'zipcode' => '',
'service_zipcode' => '',
'phone' => '',
'fax' => '',
'email' => '',
'facebook' => '',
'twitter' => '',
'linkedin' => '',
'gplus' => '',
'latitude' => '',
'longitude' => '',
'url' => '',
'created_at' => '2019-04-22 07:29:33',
'updated_at' => '2019-04-22 07:32:25',
),
Array
(
'id' => 12,
'post_id' => 317,
'location' => 'Savannah, Georgia',
'address' => '834 Northside Dr. East, Statesboro',
'city' => 'Savannah',
'state' => 'Georgia',
'state_code' => 'GA',
'country' => 'USA',
'zipcode' => 30458,
'service_zipcode' => '',
'phone' => '',
'fax' => '',
'email' => '',
'facebook' => '',
'twitter' => '',
'linkedin' => '',
'gplus' => '',
'latitude' => '',
'longitude' => '',
'url' => '',
'created_at' => '2019-04-22 07:15:43',
'updated_at' => '2019-04-22 07:18:11',
)
);
$arr = array_column($locations, "state", "city");
asort($arr);
$prev = null;
foreach($arr as $city => $state){
if($state != $prev){
echo PHP_EOL . PHP_EOL . $state . PHP_EOL;
$prev = $state;
}
echo "---" . $city . PHP_EOL;
}
- Output for 7.1.25 - 7.1.28, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Georgia
---Atlanta
---Savannah
Georigia
---Augusta
Texas
---Huston
preferences:
207.21 ms | 403 KiB | 162 Q