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 ?

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
  • ¥15 怀疑手机被监控,请问怎么解决和防止
  • ¥15 Qt下使用tcp获取数据的详细操作
  • ¥15 idea右下角设置编码是灰色的
  • ¥15 全志H618ROM新增分区