Two arrays in foreach loop

后端 未结 22 1871
不思量自难忘°
不思量自难忘° 2020-11-22 04:48

I want to generate a selectbox using two arrays, one containing the country codes and another containing the country names.

This is an example:

22条回答
  •  野的像风
    2020-11-22 05:34

    Why not just consolidate into a multi-dimensional associative array? Seems like you are going about this wrong:

    $codes = array('tn','us','fr');
    $names = array('Tunisia','United States','France');
    

    becomes:

    $dropdown = array('tn' => 'Tunisia', 'us' => 'United States', 'fr' => 'France');
    

提交回复
热议问题