dongtiao6362 2017-08-14 04:31
浏览 50
已采纳

如何在php中连接两个数组? [重复]

This question already has an answer here:

I want to concatenate two arrays like this:

$cars=array("Volvo","BMW","Toyota");
$speed=array("210","220","330");
$merge=array_merge($cars,$speed);

Expected output:

array(
    0=>Volvo 210
    1=>BMW 220 
    2=>Toyota 330
)
</div>
  • 写回答

5条回答 默认 最新

  • douxian9060 2017-08-14 05:04
    关注

    You can also try this simplest one. Here we are using array_map to achieve desired output

    Try this code snippet here

    <?php
    
    $cars = array('Volvo', 'BMW', 'Toyota');
    $speed = array('210', '220', '330');
    
    $result = array_map(function($car, $speed) {
        return $car . ' ' . $speed;
    }, $cars, $speed);
    
    var_dump($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?