The answer comes from the server in json format, you need to display only the balance, how to do it?

I do var_dump($smsaero_api->balance()); :

 array(3) { ["success"]=> bool(true) ["data"]=> array(1) { ["balance"]=> $ float(3.46) } ["message"]=> NULL } 

I tried to derive as follows:

 $obj = json_decode($smsaero_api->balance()); print $obj->{'balance'}; 
  • can brute force the foreach array. but I don't know how, tell me pliz - Ilya Pim

1 answer 1

You have a mistake in that you specify not the full path to the value, you miss the data element:

Full version of the code:

 $obj = $smsaero_api->balance(); echo $obj['data']['balance']; 
  • include_once ('SmsaeroApiV2.class.php'); use SmsaeroApiV2 \ SmsaeroApiV2; $ smsaero_api = new SmsaeroApiV2 ('mail @ mail', 'FeBa6vM', 'GO'); var_dump ($ smsaero_api-> balance ()) // Balance request $ obj = json_decode ($ smsaero_api-> balance ()) -> data-> balance; print $ obj -> {'balance'}; - Ilya Pim
  • @ IlyaPim, I corrected the answer, look - Let's say Pie
  • @ IlyaPim, you brought the value $obj = json_decode($smsaero_api->balance())->data->balance , why do you make a request to it again through print $obj->{'balance'}; , just type print $obj; - Let's say Pie
  • does not print anything :( white screen, and if var_dump ($ smsaero_api-> balance ()); then output the array - Ilya Pim
  • one
    eee, thanks bro! - Ilya Pim