1

我想创建一个看起来像这样的数组

 $appsByOs = Array(
                  osName1 =>Array(0=>app1,1=>app2)
                  osName2 =>Array(0=>app1,1=>app2)
                  etc.....
  )

我怎么能在 foreach 循环中做到这一点?

  foreach($osInstanceNames as $osInstanceName){
                    $appNames(array of app names for current os)

            }

谢谢

4

2 回答 2

0

您需要做的就是这个。

 $appsByOs = Array();
 foreach($osInstanceNames as $osInstanceName){
                     $appsByOs[$osInstanceName] = $appNames;

 }
于 2012-05-03T14:08:58.467 回答
0

恢复上一篇文章并为一个操作系统实例添加多个应用程序的可能性

 $appsByOs = Array(); 
 foreach($osInstanceNames as $osInstanceName){ 
                     $appsByOs[$osInstanceName][] = $appNames; 

 } 
于 2012-05-03T14:23:17.567 回答