Saturday, April 15, 2017

hoe to solve it in php

hello i am using this code

    $yearRes=DB::table('order')
            ->select(DB::raw("year(created_at) as y"))
            ->orderBy("created_at")
            ->groupBy(DB::raw("year(created_at)"))->get();
    foreach ($yearRes as $key => $value) {
        $totalOrder[]=DB::table('order')->select(DB::raw("year(created_at) as y,sum(item_price) as p,count(id) as i"))->whereYear('created_at', '=', $value->y)->get();
    }

but it show me [[{"y":2016,"p":15050,"i":11}],[{"y":2017,"p":8440,"i":3}]]

when i use this code

 $abc=json_encode($totalOrder);
  $a=rtrim($abc);
  $title=explode('[', $a);
  $c=implode('', $title);
  $ac=rtrim($c,']');

then result {"y":2016,"p":15050,"i":11}],{"y":2017,"p":8440,"i":3} but i want to output {"y":2016,"p":15050,"i":11},{"y":2017,"p":8440,"i":3} please help me



via Nurkarim

Advertisement