duan20081202 2016-10-11 18:09
浏览 75
已采纳

如何在php中的一个多维数组中组合数组?

I have three arrays Like the following:-

Array
(
    [0] => option1
    [1] => option2
    [2] => option3
)

Array
(
    [0] => value1
    [1] => value2
    [2] => value3
)

Array
(
    [0] => 15
    [1] => 43
    [2] => 12
)

I want to Combine these arrays like following:

Array(

        [0] =>Array(
                    [0] => option1
                    [1] => value1
                    [2] => 15
        )

        [1] =>Array(
                    [0] => option2
                    [1] => value2
                    [2] => 43
        )

        [2] =>Array(
                    [0] => option3
                    [1] => value3
                    [2] => 12
        )
)
  • 写回答

1条回答 默认 最新

  • dsdapobp26141 2016-10-11 18:31
    关注

    I always like this behavior of array_map() function because it helps me a lot :).See Example #4 Creating an array of arrays at http://php.net/manual/en/function.array-map .I hope this fits your requirement perfectly. :)

    $array = array('option1','option2','option3');
    $array2 = array('value1','value2','value3');
    $array3 = array(15,40,12);
    
    $result = array_map(null,$array,$array2,$array3); //see magic here 
    print '<pre>';
    print_r($result);
    print '</pre>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分