Two arrays in foreach loop

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

    Instead of foreach loop, try this (only when your arrays have same length).

    $number = COUNT($_POST["codes "]);//count how many arrays available
    if($number > 0)  
    {  
      for($i=0; $i<$number; $i++)//loop thru each arrays
      {
        $codes =$_POST['codes'][$i];
        $names =$_POST['names'][$i];
        //ur code in here
      }
    }
    

提交回复
热议问题