Two arrays in foreach loop

后端 未结 22 1768
不思量自难忘°
不思量自难忘° 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:42

    All fully tested

    3 ways to create a dynamic dropdown from an array.

    This will create a dropdown menu from an array and automatically assign its respective value.

    Method #1 (Normal Array)

    'Tunisia','us'=>'United States','fr'=>'France');
    
    echo '';
     
    ?>
    


    Method #2 (Normal Array)

    
    


    Method #3 (Associative Array)

     'Tunisia',
         'us' => 'United States',
         'fr' => 'France'
    );
    
    echo '';
    ?>
    

提交回复
热议问题