I have a JSON decoded array in php with foreach that includes a select option in a form every time I select an option from this drop down it returns the last value in the list. The option is just the selector not the value I'm trying to save. I'm trying to save the flatnumber,building,address1,address2,town,county variables into hidden inputs. How do I go about this? Any help really appreciated!!
$api_url = 'http://rest.api?postcode=' . urlencode($_GET['postcode']);
$api_json = file_get_contents($api_url);
$api_array = json_decode($api_json, true);
$address = $api_array['addresses'];
foreach($address as $addresses){
echo '<option>'.$addresses['address'].'</option>';
$flatnumber = $addresses['flatNumber'];
$address1 = $addresses['building'];
$address2 = $addresses['address1'];
$town = $addresses['town'];
$county = $addresses['county'];
}