I'm in a bind..
This is the output I would like;
Array
(
[country] => Array(
[0] => England
[1] => Channel Islands
)
[gor] => Array(
[0] => North East
[1] => North West
)
[parliamentaryconstituency] => Array(
[0] => Aldershot
[1] => Aldridge-Brownhills
)
)
This is what I currently have;
Array
(
[0] => Array
(
[country] => England
)
[1] => Array
(
[country] => Channel Islands
)
[2] => Array
(
[gor] => North East
)
[3] => Array
(
[gor] => North West
)
[4] => Array
(
[parliamentaryconstituency] => Aldershot
)
[5] => Array
(
[parliamentaryconstituency] => Aldridge-Brownhills
)
)
My code is;
foreach ($input as $key => $value) {
foreach ($value as $subkey => $subvalue) {
switch ($key)
{
case 'country':
$country = Country::description($subvalue)->get()->first();
array_push($new_input, array('country' => $country->description));
break;
case 'gor':
$gor = Gor::description($subvalue)->get()->first();
array_push($new_input, array('gor' => $gor->description));
break;
case 'parlc':
$parliamentaryconstituency = ParliamentaryConstituency::description($subvalue)->get()->first();
array_push($new_input, array('parliamentaryconstituency' => $parliamentaryconstituency->description));
break;
}
}
}
I considered array_push($new_input['country'], $country->description); and having $new_input['country'] above the foreachs but that will output an empty country array if no countries are selected and I'd prefer it not to appear at all if that's the case.