dtyqflrr775518 2013-12-12 15:30 采纳率: 100%
浏览 38
已采纳

以关联方式映射数组

I have the following array defined.

$a = Array
(
    [0] => 30:27
    [1] => 29:28
    [2] => 30:27
)
$b = Array
(
    [0] => 102186
    [3] => 102991
    [4] => 102241
)

I have used array_map($a,$b); But not what i want the result comes.

Always first to first key, second to second key, third to third key, I expect the following result...

$ab = $b = Array
    (
        [0] => 102186 [30:27]
        [1] => 102991 [29:28]
        [2] => 102241 [30:27]
    ) 
  • 写回答

3条回答 默认 最新

  • duanshan3427 2013-12-12 15:36
    关注

    Just loop over the 1st array and add the corresponding value from the 2nd one. You can actually use array_map for this:

    $ab = array_map(function($aVal, $bVal){
        return "$bVal [$aVal]";
    }, $a, $b);
    

    DEMO: https://eval.in/78684

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题