Blog

Some of my thought on technology and programming.

Ever needed to create a dropdown (<select>) of British counties? It's a proper pain in you-know-what. Below, is a PHP array compatible with Laravel's Form::select().

The output of this will be a dropdown with countied grouped into countries.

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
<?php
$counties => array(
	"England" => array(
		"avon" => "Avon",
		"bedfordshire" => "Bedfordshire",
		"berkshire" => "Berkshire",
		"buckinghamshire" => "Buckinghamshire",
		"cambridgeshire" => "Cambridgeshire",
		"cheshire" => "Cheshire",
		"cleveland" => "Cleveland",
		"cornwall" => "Cornwall",
		"cumbria" => "Cumbria",
		"derbyshire" => "Derbyshire",
		"devon" => "Devon",
		"dorset" => "Dorset",
		"durham" => "Durham",
		"east sussex" => "East Sussex",
		"essex" => "Essex",
		"gloucestershire" => "Gloucestershire",
		"hampshire" => "Hampshire",
		"herefordshire" => "Herefordshire",
		"hertfordshire" => "Hertfordshire",
		"isle of wight" => "Isle of Wight",
		"kent" => "Kent",
		"lancashire" => "Lancashire",
		"leicestershire" => "Leicestershire",
		"lincolnshire" => "Lincolnshire",
		"london" => "London",
		"merseyside" => "Merseyside",
		"middlesex" => "Middlesex",
		"norfolk" => "Norfolk",
		"northamptonshire" => "Northamptonshire",
		"northumberland" => "Northumberland",
		"north humberside" => "North Humberside",
		"north yorkshire" => "North Yorkshire",
		"nottinghamshire" => "Nottinghamshire",
		"oxfordshire" => "Oxfordshire",
		"rutland" => "Rutland",
		"shropshire" => "Shropshire",
		"somerset" => "Somerset",
		"south humberside" => "South Humberside",
		"south yorkshire" => "South Yorkshire",
		"staffordshire" => "Staffordshire",
		"suffolk" => "Suffolk",
		"surrey" => "Surrey",
		"tyne and wear" => "Tyne and Wear",
		"warwickshire" => "Warwickshire",
		"west midlands" => "West Midlands",
		"west sussex" => "West Sussex",
		"west yorkshire" => "West Yorkshire",
		"wiltshire" => "Wiltshire",
		"worcestershire" => "Worcestershire"
	),
	"Wales" => array(
		"clwyd" => "Clwyd",
		"dyfed" => "Dyfed",
		"gwent" => "Gwent",
		"gwynedd" => "Gwynedd",
		"mid glamorgan" => "Mid Glamorgan",
		"powys" => "Powys",
		"south glamorgan" => "South Glamorgan",
		"west glamorgan" => "West Glamorgan"
	),
	"Scotland" => array(
		"aberdeenshire" => "Aberdeenshire",
		"angus" => "Angus",
		"argyll" => "Argyll",
		"ayrshire" => "Ayrshire",
		"banffshire" => "Banffshire",
		"berwickshire" => "Berwickshire",
		"bute" => "Bute",
		"caithness" => "Caithness",
		"clackmannanshire" => "Clackmannanshire",
		"dumfriesshire" => "Dumfriesshire",
		"dunbartonshire" => "Dunbartonshire",
		"east lothian" => "East Lothian",
		"fife" => "Fife",
		"inverness-shire" => "Inverness-shire",
		"kincardineshire" => "Kincardineshire",
		"kinross-shire" => "Kinross-shire",
		"kirkcudbrightshire" => "Kirkcudbrightshire",
		"lanarkshire" => "Lanarkshire",
		"midlothian" => "Midlothian",
		"moray" => "Moray",
		"nairnshire" => "Nairnshire",
		"orkney" => "Orkney",
		"peeblesshire" => "Peeblesshire",
		"perthshire" => "Perthshire",
		"renfrewshire" => "Renfrewshire",
		"ross-shire" => "Ross-shire",
		"roxburghshire" => "Roxburghshire",
		"selkirkshire" => "Selkirkshire",
		"shetland" => "Shetland",
		"stirlingshire" => "Stirlingshire",
		"sutherland" => "Sutherland",
		"west lothian" => "West Lothian",
		"wigtownshire" => "Wigtownshire"
	),
		"Northern Ireland" => array(
		"antrim" => "Antrim",
		"armagh" => "Armagh",
		"down" => "Down",
		"fermanagh" => "Fermanagh",
		"londonderry" => "Londonderry",
		"tyrone" => "Tyrone"
	)

);

This list is based on the wonderful list provided by carronmedia.com (which is, in turn based on this Wikipedia article: http://en.wikipedia.org/wiki/List_of_counties_of_the_United_Kingdom).

I hope this helps.