需要在forloop中实现数组推送

时间:2017-06-02 19:42:09

标签: laravel-5

----------------------代码------------------------ -

public function event_requests(){
  $Uid = Input::get('Uid');
  $token = Input::get('token_code');
  $time = Input::get('time');

  if(App_user::where('ID', '=', $Uid)->where('token_code', '=', $token)->count() > 0){
    $result = DB::table('Ball_invites')
      ->join('Ball_users','Ball_users.ID', '=', 'Ball_invites.people')
      ->select('Ball_users.*', 'Ball_invites.Eid')
      ->Where('Ball_users.Pid', '=', $Uid)
      ->orWhere('Ball_users.ID', '=', $Uid)
      ->get();

    foreach ($result as $val){
      $eis[] = $val->Eid;
      $eids = array_unique($eis);
    }

    $event = DB::table('Ball_event')->whereIn('ID', $eids)->get();

    $resultdataa = array();

    foreach($result as $new){
      $resultdataa[$new->Eid] = $new;
    }

    $resultdata = json_decode(json_encode($resultdataa), true);

    $data = array();

    foreach($event as $key){
      $data[$key->ID] = $key;
    }

    $dataa = json_decode(json_encode($data), true);

    $final = array();

    foreach($dataa as $key2=>$val2){
      foreach($resultdata as $key1=>$val1){
        if($key2 == $key1){
          $arrs[] = $val2;
          $arrss[] = $val1;
          print_r($val1);
        }
      }
    }

    return Response::json(array('status'=>200,'result'=>$final));
  } else {
    return Response::json(array('status'=>'401','msg'=>'session expired'));
  }
}

---------------------需要这样的记录----------------------

编辑器注意:下面的数据结构看起来好像是JSON, 但我不确定在错误的位置如何制作嵌套数组。

{
  "status": 200,
  "result": [
    {
      "ID": 63,
      "Uid": 86,
      "event_type": 1,
      "event_title": "Testing",
      "event_location": "Home",
        [
          {
            "ID": 141,
            "Pid": 139,
            "fname": "Veronica",
            "lname": "khiwani",
            "nick_name": "Ronnie",
          },
          {
            "ID": 141,
            "Pid": 139,
            "fname": "Veronica",
            "lname": "khiwani",
            "nick_name": "Ronnie",
          }
        ]
      },
      {
        "ID": 64,
        "Uid": 139,
        "event_type": 2,
        "event_title": "cricket match",
        "event_location": "london",
      }
    ]
  }

0 个答案:

没有答案