array_combine is return only last value

前端 未结 2 1372
心在旅途
心在旅途 2021-01-27 12:29

I have two different array for foreach loop so i decide to combine them and run in to foreach loop together but it\'s returning only last

相关标签:
2条回答
  • 2021-01-27 12:37

    You cannot have the same key multiple times in an array.

    Do this instead:

    foreach (array_combine($FileName, $FileType) as $Name => $Type) {
           echo $Type .":". $Name;
    }
    
    0 讨论(0)
  • 2021-01-27 12:39

    That's not how array_combine works.

    You can simply do

      foreach($FileName as $id=>$Name)
      {
          echo $FileType[$id] .":". $Name;
      }
    

    Assuming both arrays are of same size and same keys

    0 讨论(0)
提交回复
热议问题