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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?