There is a string whose var_dump() shows:

 object(stdClass)#1 (1) { ["response"]=> int(112) } 

How do I get to field 112 ?

Full code:

 $ress = sendMessege($text, $user_id); function sendMessege($text, $id) { $url = "https://api....."; $data = curlGet($url); return $data; } function curlGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $response = curl_exec($curl); curl_close($curl); return $response; } 
  • 2
    Arrow, as in the classes: -> response - zhenyab
  • I will now be a psychic but when you do json_encode($json,true) , put the last parameter to convert to an array, and work with it. - Naumov
  • @zhenyab answer then post - Naumov
  • and it pulls the answer? - zhenyab 1:01 pm
  • The arrow returns NULL - antonin14d

2 answers 2

You have received the answer in the form of an object: $data->response
To convert the answer to an array, try: $ret = (array)$data;

  • Convening it turned out, and $ ret [0] gives {"response": 129}, but $ ret [0] ['response'] writes Warning: Illegal string offset 'response' - antonin14d
  • @ antonin14d as a class parameter should work for an example here see sandbox.onlinephpfunctions.com/code/… - Naumov

If I understand correctly, then you have an array, I think you can apply like this

 $stdClass["response"] 
  • in php 5.4 writes, incompatible with the version of php - antonin14d
  • This is an object and not an array, so downvote - Naumov