I want to generate a selectbox
using two arrays, one containing the country codes and another containing the country names.
This is an example:
foreach
operates on only one array at a time.
The way your array is structured, you can array_combine()
them into an array of key-value pairs then foreach
that single array:
foreach (array_combine($codes, $names) as $code => $name) {
echo '';
}
Or as seen in the other answers, you can hardcode an associative array instead.