mercis

mercis

好好干,天天有米饭

  • 财富值

    1875

  • 威望值

    80

  • 总积分

    2875

个人信息

  • 回答了问题 composer 问题

    直接把 require....添加到composer.json文件中, 在项目根目录composer update 一下

    47分钟前查看
  • 回复了 的回答
    $arr1 = Array(
        0 => Array
        (
            'created_at' => '2016 - 08',
            'a' => 31900.00
        ),
        1 => Array
        (
            'created_at' => '2016 - 09',
            'a' => 45400.00
        ),
        2 => Array
        (
            'created_at' => '2016 - 10',
            'a' => 69489.00
        ));
    
    $arr2 = Array(
        0 => Array
        (
            'created_at' => '2016 - 08',
            'b' => 21900.00
        ),
        1 => Array
        (
            'created_at' => '2016 - 09',
            'b' => 25400.00
        ));
    $arr3 = [];
    foreach ($arr1 as $key => $val) {
        $arr3[$key]['created_at'] = $val['created_at'];
        $arr3[$key]['a'] = $val['a'];
        foreach ($arr2 as $v) {
            if ($arr3[$key]['created_at'] == $v['created_at']) {
                $arr3[$key]['b'] = $v['b'];
            } else {
                $arr3[$key]['b'] = '';
            }
        }
    }
    var_dump($arr3);
    

    结果 :

    array (size=3)
      0 => 
        array (size=3)
          'created_at' => string '2016 - 08' (length=9)
          'a' => float 31900
          'b' => string '' (length=0)
      1 => 
        array (size=3)
          'created_at' => string '2016 - 09' (length=9)
          'a' => float 45400
          'b' => float 25400
      2 => 
        array (size=3)
          'created_at' => string '2016 - 10' (length=9)
          'a' => float 69489
          'b' => string '' (length=0)
          
    

    这个有意思了,还有没有别的解法

    53分钟前查看
  • 2017-10-20 已签到
    连续签到12天,获得了20个金钱
    1小时前
  • 2017-10-19 已签到
    连续签到11天,获得了20个金钱
    1天前
  • 2017-10-18 已签到
    连续签到10天,获得了20个金钱
    2天前
  • 2017-10-17 已签到
    连续签到9天,获得了20个金钱
    2017-10-17 08:37
  • 2017-10-16 已签到
    连续签到8天,获得了20个金钱
    2017-10-16 08:52
  • 2017-10-15 已签到
    连续签到7天,获得了20个金钱
    2017-10-15 15:01
  • 2017-10-14 已签到
    连续签到6天,获得了20个金钱
    2017-10-14 19:33
  • 回复了 的回答
    $arr1 = Array(
        0 => Array
        (
            'created_at' => '2016 - 08',
            'a' => 31900.00
        ),
        1 => Array
        (
            'created_at' => '2016 - 09',
            'a' => 45400.00
        ),
        2 => Array
        (
            'created_at' => '2016 - 10',
            'a' => 69489.00
        ));
    
    $arr2 = Array(
        0 => Array
        (
            'created_at' => '2016 - 08',
            'b' => 21900.00
        ),
        1 => Array
        (
            'created_at' => '2016 - 09',
            'b' => 25400.00
        ));
    $arr3 = [];
    foreach ($arr1 as $key => $val) {
        $arr3[$key]['created_at'] = $val['created_at'];
        $arr3[$key]['a'] = $val['a'];
        foreach ($arr2 as $v) {
            if ($arr3[$key]['created_at'] == $v['created_at']) {
                $arr3[$key]['b'] = $v['b'];
            } else {
                $arr3[$key]['b'] = '';
            }
        }
    }
    var_dump($arr3);
    

    结果 :

    array (size=3)
      0 => 
        array (size=3)
          'created_at' => string '2016 - 08' (length=9)
          'a' => float 31900
          'b' => string '' (length=0)
      1 => 
        array (size=3)
          'created_at' => string '2016 - 09' (length=9)
          'a' => float 45400
          'b' => float 25400
      2 => 
        array (size=3)
          'created_at' => string '2016 - 10' (length=9)
          'a' => float 69489
          'b' => string '' (length=0)
          
    

    这段代码只是当时的应用场景(已知两个数组),深究的话还是有很多问题,不过还是感谢你的意见

    2017-10-13 08:48查看

总监

等级规则
2875/500057.5% Complete

资料完整度

100/100100% Complete

用户活跃度

30/10030% Complete

Ta的关注

9

Ta的粉丝

2

Ta的访客

13