dr9379 2012-12-20 17:17
浏览 22
已采纳

当一个比第二个大两倍时,预先取两个数组

Ok so I have two arrays, and the second one is allways twice larger than first one:

$items1 = array('1', '2', '3');
$items2 = array('a', 'b', 'c', 'd', 'e', 'f');

I know that i can foreach two arrays with same items count like this:

foreach ($items1 as $key => $item1)
{
echo $item1 . $items2[$key] . ', ';
}

This will give result like this: 1a, 2b, 3c.... But how to foreach thos two arrays to get result like this: 1ab, 2cd, 3ef? aka echo first item from $items1 array, an then two from $items2.

  • 写回答

2条回答 默认 最新

  • douyingzhan5905 2012-12-20 17:20
    关注

    You could write:

    foreach ($items1 as $i => $item1)
    {
        echo $item1 . $items2[$i * 2] . $items2[$i * 2 + 1] . ', ';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架