PHP: Best way to iterate two parallel arrays?

前端 未结 3 1899
眼角桃花
眼角桃花 2020-12-05 12:24

As seen in this other answer, there are several ways to iterate two same-sized arrays simultaneously; however, all of the methods have a rather significant pitfall. Here ar

3条回答
  •  星月不相逢
    2020-12-05 12:59

    As of PHP 5.5 you can do this:

    foreach (array_map(null, $array1, $array2) as list($item1, $item2))
    {
        var_dump($item1);
        var_dump($item2);
    }
    

    http://us3.php.net/manual/en/control-structures.foreach.php#control-structures.foreach.list

提交回复
热议问题