doulianxing4015 2015-04-04 02:25
浏览 40
已采纳

加入2个多维数组php?

i have 2 multidimensionals arrays

eg:

$data[0] = "value1, value2, value3, value4, value5";

$data[1] = "name1, name2, name3, name4, name5";

how can i join them together so that each value in data[0] takes the name from data[1] output should be foreach value:

$newarray[0] = Array('value'=>'value1', 'name'=>'name1'); 
$newarray[1] = Array('value'=>'value2', 'name'=>'name2');

and so on

Thanx ;)

  • 写回答

1条回答 默认 最新

  • dongren9739 2015-04-04 03:03
    关注

    Well, I may have misunderstood your question, but if I understand it correctly then something like this should do it:

    $values = preg_split('/,\s+/', $data[0]);
    $names  = preg_split('/,\s+/', $data[1]);
    
    $length = min(count($values), count($names));
    $newarray = array();
    for ($i = 0; $i < $length; $i++) {
        $newarray[] = array(
            'value' => array_shift($values),
            'name' => array_shift($names),
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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