PHP: array_merge() in alternate order (zip order)?

前端 未结 1 575
一生所求
一生所求 2020-12-22 06:08

Is there a native PHP function to zip merge two arrays?

Look at the following example:

$a = array(\"a\",\"b\",\"c\");
$b = array(\"d\",\"e\",\"f\");
         


        
相关标签:
1条回答
  • 2020-12-22 06:13

    There is no PHP native function for this purpose. However according to the comment of @Mark Baker there is a short possibility to implement this:

    $a = array("a","b","c");
    $b = array("d","e","f");
    $c = array("g","h","i");
    
    function array_zip(...$arrays) {
        return array_merge(...array_map(null, ...$arrays));
    }
    
    var_dump(array_zip($a,$b,$c));
    
    0 讨论(0)
提交回复
热议问题