dqx24298 2018-06-11 13:40
浏览 30
已采纳

如何从Variable中删除数组中的数组?

I want to remove array from arrays but array is in $variable. I did not find any example which has array in array for $variable.

Function:

     public function firstHourTrades()
{

    $user_id = Auth::user()->id;
    $first_hour = DB::table('finaltrade')
        ->select(DB::raw('count(*) as first'))
        ->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
        ->where('finaltrade.user_id', $user_id)
        ->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '>=', DB::raw('exchanges.start_time'))
        ->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '<=', DB::raw("ADDTIME(exchanges.start_time, '01:00:00')"))
        ->get();


    $last_hour = DB::table('finaltrade')
        ->select(DB::raw('count(*) as last'))
        ->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
        ->where('finaltrade.user_id', $user_id)
        ->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '<=', DB::raw('exchanges.close_time'))
        ->whereTime(DB::raw('IF(finaltrade.buy_datetime<finaltrade.sell_datetime, finaltrade.buy_datetime, finaltrade.sell_datetime) '), '>=', DB::raw("SUBTIME(exchanges.close_time, '01:00:00')"))
        ->get();


    $other_hours = DB::table('finaltrade')
        ->select(DB::raw('count(*) as other'))
        ->join('exchanges', 'finaltrade.exchange_id', '=', 'exchanges.id')
        ->where('finaltrade.user_id', $user_id)
        ->whereRaw('finaltrade.created_at NOT BETWEEN exchanges.start_time AND DATE_ADD(exchanges.start_time, INTERVAL 1 HOUR)')
        ->whereRaw('finaltrade.created_at NOT BETWEEN exchanges.close_time AND DATE_SUB(exchanges.close_time, INTERVAL 1 HOUR)')
        ->get();

    $data = [$first_hour,$last_hour,$other_hours];
    return response()->json($data );
}

OUTPUT of above function :

[[{"first":1}],[{"last":0}],[{"other":4}]]

I want to remove array in array, what i do in my function?

  • 写回答

2条回答 默认 最新

  • dqtu14636 2018-06-11 13:44
    关注

    If your queries result as a single row which i guess yes because you are not using group by then you can use first() instead of get()

    Output will be

    [{"first":1},{"last":0},{"other":4}]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据