如何访问数组中的json?

时间:2019-06-10 07:04:28

标签: php json laravel

我正在尝试访问嵌套数组中的json,但是它尚无法正常工作。

我正在laravel中进行开发,

public function rave(Request $request){


    $vars = [

       'id' => Request::get('id'),
       'txref' => Request::get('txRef'),
       'flwref' => Request::get('flwRef'),
       'created_at' => Request::get('createdAt'),
       'amount' => Request::get('amount'),
       'status' => Request::get('status'),
       'name' => Request::get('fullName'),
       'email' => Request::get('customer'),

    ];

除了nameemail以外,我都可以查看所有内容并显示在视图中

"customer":{
    "id":15672,
    "phone":"7667866 ",
    "fullName":"john doe ",
    "customertoken":null,
    "email":"kely@gmail.com",
    "createdAt":"2019-06-09T08:28:56.000Z",
    "updatedAt":"2019-06-09T08:28:56.000Z",
    "deletedAt":null,
    "AccountId":33519
},

如何访问customer下的数据,因为

'name' => Request::get('fullName'),
'email' => Request::get('customer'),

似乎不像其他人那样工作

1 个答案:

答案 0 :(得分:3)

您将Request $request用作函数参数,

并检查

的输出
echo $request->input('customer.fullName');
echo $request->input('customer.email');