Jump to content

php print_r


jafarsalam

Recommended Posts

hi;

 

i have :

 

echo '<pre>';

  print_r($response);

echo '</pre>';

 

and response is :

 

Net_Ping_Result Object

(

    [_icmp_sequence] => Array

        (

            [1] => 183

            [2] => 158

            [3] => 180

        )

 

    [_target_ip] => 209.35.123.XXX

    [_bytes_per_request] => 64

    [_bytes_total] => 192

    [_ttl] => 48

    [_raw_data] => Array

        (

            [0] => PING xxxxxxxxxx.com (209.35.123.XXX) 56(84) bytes of data.

            [1] => 64 bytes from xxxxxxxxxx.com (209.35.123.XXX): icmp_seq=1 ttl=48 time=183 ms

            [2] => 64 bytes from xxxxxxxxxx.com (209.35.123.XXX): icmp_seq=2 ttl=48 time=158 ms

            [3] => 64 bytes from xxxxxxxxxx.com (209.35.123.XXX): icmp_seq=3 ttl=48 time=180 ms

            [4] =>

            [5] => --- xxxxxxxxxx.com ping statistics ---

            [6] => 3 packets transmitted, 3 received, 0% packet loss, time 2000ms

            [7] => rtt min/avg/max/mdev = 158.377/173.917/183.278/11.070 ms

        )

 

    [_sysname] => linux

    [_round_trip] => Array

        (

            [min] => 158.377

            [avg] => 173.917

            [max] => 183.278

            [stddev] => 11.07

        )

 

    [_transmitted] => 3

    [_received] => 3

    [_loss] => 0

)

 

 

How can i print only

 

            [3] => 64 bytes from xxxxxxxxxx.com (209.35.123.XXX): icmp_seq=3 ttl=48 time=180 ms

 

 

and

 

            [avg] => 173.917

 

thank for any help !

jeff

 

 

Link to comment
https://forums.phpfreaks.com/topic/85769-php-print_r/
Share on other sites

You need to drill down through the multi-dimensional array.

 

echo $response['_raw_data'][3]

 

Just use the array keys to get their values. I'll let you get the avg because I can't really tell the path to it.

 

EDIT: I tried to review, but pressed the button too quickly :)

 

Jeremy

Link to comment
https://forums.phpfreaks.com/topic/85769-php-print_r/#findComment-437768
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.