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'];

 

}

Link to comment
Share on other sites

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);

Edited by spfoonnewb
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.