Jump to content

Hellp Need Seperate Ip With Comma


rastaman46

Recommended Posts

Yes its array

 

foreach ($returnStats['listener'] as $listener)

{

$listeners['LISTENERS'] = array(

'HOSTNAME' => (string) $listener->HOSTNAME,

'USERAGENT' => (string) $listener->USERAGENT,

'CONNECTTIME' => (string) $listener->CONNECTTIME,

'POINTER' => (string) $listener->POINTER,

'UID' => (string) $listener->UID,

);

echo $listeners['LISTENERS']['HOSTNAME'];

 

}

You can either build your own array to implode (use a key based recursive implode) or build the string yourself. Building the string yourself in this case is easiest assuming you needed that second listeners array rebuilt. Also, you should really validate that IP (make sure it's an IP in the correct format) and/or use prepared statements.

 

<?php
//Assume the dataSet appears like this based upon the provided foreach.
$returnStats = array(
   'listener' => array(
       (object) array(
           'HOSTNAME' => '192.168.1.1',
           'USERAGENT' => 'Google Chrome',
           'CONNECTTIME' => '60',
           'POINTER' => '0',
           'UID' => '1Z5548488484'
       ),
       (object) array(
           'HOSTNAME' => '192.168.1.2',
           'USERAGENT' => 'Mozilla Firefox',
           'CONNECTTIME' => '120',
           'POINTER' => '0',
           'UID' => '1Z5584844484'
       )
   )
);

$listeners = array();
$ipStr = 'WHERE IN (';
foreach ($returnStats['listener'] as $listener) {
   $listeners[] = array(
       'HOSTNAME' => (string) $listener->HOSTNAME,
       'USERAGENT' => (string) $listener->USERAGENT,
       'CONNECTTIME' => (string) $listener->CONNECTTIME,
       'POINTER' => (string) $listener->POINTER,
       'UID' => (string) $listener->UID
   );
   $ipStr .= "'{$listener->HOSTNAME}',";
}
$ipStr = substr($ipStr, 0, -1).')';

var_dump($ipStr);

//You can use the listeners array if you need it, but you shouldn't define a key.
var_dump($listeners);

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.