imploding multidemential array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

imploding multidemential array

Post by GeXus »

I have a result set from a DB that returns the following array.... how do I implode this into a comma delimited string? Thanks!

Code: Select all

Array
(
    [0] => Array
        (
            [user_id] => 2
        )

    [1] => Array
        (
            [user_id] => 5
        )

    [2] => Array
        (
            [user_id] => 11
}
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: imploding multidemential array

Post by Gargoyle »

multidemential
lol :)

other than that, use implode(array()) on the whole thing, user serialize() or array_walk() or do it the old-fashioned way:

Code: Select all

$a = array();
foreach(($arr as $v)
{
$a[] = $v['user_id'];
}
$a = implode(',',$a);
print_r($a);
Post Reply