Recover Data from Json Return

Asked

Viewed 85 times

0

I’m getting a return from a JSON URL, but I’m not able to recover the answers , I only get the first array and then there’s another array that I’m not able to recover

Code

   $json_file = file_get_contents("http://servidor.sys.net/sendsms?username=xxx&password=xxxx&phonenumber=999999999&message=ssssssss");

$json_str = json_decode($json_file, true);


var_dump( $json_str );

This and the return.

 array(2) {
  ["message"]=>
  string(8) "ssssssss"
  ["report"]=>
  array(1) {
    [0]=>
    array(1) {
      [1]=>
      array(1) {
        [0]=>
        array(4) {
          ["port"]=>
          string(7) "gsm-2.2"
          ["phonenumber"]=>
          string(11) "999999999"
          ["time"]=>
          string(19) "2017-08-04 07:34:35"
          ["result"]=>
          string(7) "success"
        }
      }
    }
  }
}
  • you’re trying to recover port, phonenumber?

  • 1

    Yeah, I’m gonna need port, phonenumber and result

1 answer

1


In that array in particular, there is a key 1 This must be your doubt, so follow the example down below:

<?php
   $array = array(
        "message" => 'ssssssss',
        "report" => array(
                array( 1 =>
                    array( 
                        array(
                              "port"=>"gsm-2.2",
                              "phonenumber"=>"999999999",
                              "time"=>"2017-08-04 07:34:35",
                              "result"=>"success"
                            )
                        )
                    )
            )
    );

   echo $array['message'];
   echo '<br>';
   echo $array['report'][0][1][0]['port'];
   echo '<br>';
   echo $array['report'][0][1][0]['phonenumber'];
   echo '<br>';
   echo $array['report'][0][1][0]['time'];
   echo '<br>';
   echo $array['report'][0][1][0]['result'];

Online Example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.