dsfs587465
2011-02-02 07:32
浏览 25
已采纳

在CakePHP中合并2个数组

I have two arrays array1 and array2. I want to merge these two arrays into one and show the values of merged array in a dropdown. I want the values in a way that the value of first array - value of 2nd array.

e.g:

$employeePlaces1 = array(1, 2, 4,9);
$employeePlaces2 = array(3, 5, 6,7);

I want in dropdown the value as $employeePlaces1[0]-$employeePlaces2[1], $employeePlaces1[0]-$employeePlaces2[1].

    1-3,
    2-5,
    4-6, 
    9-7.

How can I do this ?

图片转代码服务由CSDN问答提供 功能建议

我有两个数组array1和array2。 我想将这两个数组合并为一个,并在下拉列表中显示合并数组的值。 我希望值的方式是第一个数组的值 - 第二个数组的值。

例如:

  $ employeePlaces1 = array  (1,2,4,9); 
 $ employeePlaces2 = array(3,5,6,7); 
   
 
 

我想在下拉列表中将值视为 <代码> $ employeePlaces1 [0] - $ employeePlaces2 [1] , <代码> $ employeePlaces1 [0] - $ employeePlaces2 [1] <预 > 1-3, 2-5, 4-6, 9-7。

我该怎么做?< / p>

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

5条回答 默认 最新

  • dongmu3457 2011-02-02 10:24
    最佳回答
    $employee1 = array(1, 2, 4, 9);
    $employee2 = array(3, 5, 6, 7);
    
    function doMerge($n, $m) {
        return $n.'-'.$m;
    }
    
    
    $c = array_map("doMerge", $employee1, $employee2);
    
    print_r($c);
    

    Or in PHP 5.3 syntax with lambda style functions:

    $c = array_map(function($n, $m) {return $n.'-'.$m;}, $employee1, $employee2);
    
    评论
    解决 无用
    打赏 举报
查看更多回答(4条)

相关推荐 更多相似问题