I am having a devil of a time trying to get my arrays to print right, but I am missing something. I am hoping another set of eyes can help me figure it out. I have this current function:

function getArrayUsers($id) {
    $sql = DB::inst()->query( "SELECT * FROM " . TP . "users WHERE id = '$id' AND confirmed = '1' AND unsubscribe ='0'" );
    $rows = array();
    while($r = $sql->fetch_assoc()) {
        $rows[] = $r['address'];
    }
    return $rows;
}

Currently, the results of this function print out like so:

Array ( [0] => test@gmail.com [1] => test2@gmail.com )

Now, I will need this output at some point, but I need to do this in two steps. First, I need the result of the function to first print out the results like so:

'test2@gmail.com','test2@gmail.com';

Then what I want to do is take my custom function's result and run it through the PHP array function to achieve the array I mentioned earlier.

I have tried several ways of trying to accomplish this, but I've been looking at it too long. The only time that I've come close was when echoing the results in the function. However, I always try to avoid that and it echos the result on the page as well, which is what I don't want. If anyone can help me with this, will greatly appreciate it.

First, I need the result of the function to first print out the results like so:

For this use the implode function:

echo implode(',', getArrayUsers($id));

The second part of the question I do not quite understand. Can you reword it?

Thanks for the code. That is part of what I need. Sorry, I did have a difficult time trying to explain it. So, what I am trying to do is grab an array of emails to put into an email script that will send an email to each user. So the end result has to be in this format in order for the system to send an email to each user in the database.

$formMailer->to = array('test1@gmail.com','test2@gmail.com','test3@gmail.com');

@broj1, thanks again. It was exactly what I needed. I finished it off by doing:

$list = implode(',', getArrayUsers($id));
$formMailer->to = array($list);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.