-1

hi guys i am facing a problem in decoding an array from a curl response and assinging value of result to variable.I want to assign the value of auth_token from the array give below to a variable in php.

{ "status": true, "result": { "daily_prize_num": 0, "daily_prize_amount": 0, "monthly_prize_num": 0, "monthly_prize_total": 0, "daily_chances": 0, "monthly_chances": 0, "chances_left": 0, "user": { "phone": "91889888888", "country_id": "2", "created_at": 1457242503, "verified": 0, "device_id": "x55769w0ecb4f9k3", "device_token": "APA91bF4ETz2QhQZ8JcbB6TQHPdYa6v7TBnEIrjRySftQrjCVuvYs7owqqTgS76cHN6xmGzzA_rkRuOYuXIo5Po0ngOqo0h_NyAORa899WAwmSgiALdXsjo", "referral_code": "", "referral_code_used": "4hTRSK", "auth_token": "8fd3bd001a3bf5a47021924a80ccb0068cf6f7ccaf19b591b8232e0bfd63aa26b4d19ee589d7ab2dd8f07317936aa76b9762446ae6372ea800a6151460baa81a", "is_active": 1, "id": 88494, "is_first_time": true, "profile_completed": false } } }

JimL
  • 2,501
  • 1
  • 19
  • 19

2 Answers2

1

Use json_decode and access the array:

$r = json_decode ($data, true);
$auth = $r ['result']['user']['auth_token'];
Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43
0
$var = json_decode('{"status":true,"result":{"daily_prize_num":0,"daily_prize_amount":0,"monthly_prize_num":0,"monthly_prize_total":0,"daily_chances":0,"monthly_chances":0,"chances_left":0,"user":{"phone":"91889888888","country_id":"2","created_at":1457242503,"verified":0,"device_id":"x55769w0ecb4f9k3","device_token":"APA91bF4ETz2QhQZ8JcbB6TQHPdYa6v7TBnEIrjRySftQrjCVuvYs7owqqTgS76cHN6xmGzzA_rkRuOYuXIo5Po0ngOqo0h_NyAORa899WAwmSgiALdXsjo","referral_code":"","referral_code_used":"4hTRSK","auth_token":"8fd3bd001a3bf5a47021924a80ccb0068cf6f7ccaf19b591b8232e0bfd63aa26b4d19ee589d7ab2dd8f07317936aa76b9762446ae6372ea800a6151460baa81a","is_active":1,"id":88494,"is_first_time":true,"profile_completed":false}}}') ;

$token = $var['result'] ['user'] ['auth_token'] ;
totemax
  • 46
  • 1
  • 3