I want to generate a selectbox
using two arrays, one containing the country codes and another containing the country names.
This is an example:
Use an associative array:
$code_names = array(
'tn' => 'Tunisia',
'us' => 'United States',
'fr' => 'France');
foreach($code_names as $code => $name) {
//...
}
I believe that using an associative array is the most sensible approach as opposed to using array_combine()
because once you have an associative array, you can simply use array_keys()
or array_values()
to get exactly the same array you had before.