我想从数组中删除数组,但数组在$variable
中。我没有找到任何在$variable
数组中包含数组的示例。
功能:
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 :
[[{"first":1}],[{"last":0}],[{"other":4}]]
我想删除数组中的数组,我在函数中执行的操作是什么?
答案 0 :(得分:0)
如果您的查询结果为单行我认为是,因为您之前没有使用群组,那么您可以使用first()
代替get()
输出
[{"first":1},{"last":0},{"other":4}]
答案 1 :(得分:0)
<?php
$prefs =
[
['fruit' => 'banana'],
['nut' => 'pecan'],
['pasta' => 'fusili']
];
$flatter = array_merge(...$prefs);
var_export($flatter);
输出:
array (
'fruit' => 'banana',
'nut' => 'pecan',
'pasta' => 'fusili',
)