NYCPHP Meetup

NYPHP.org

[nycphp-talk] Implode a column of a multi-dim array

Andrew Yochum andrew at plexpod.com
Wed Oct 26 12:00:21 EDT 2005


On Tue, Oct 25, 2005 at 05:01:01PM -0400, Cliff Hirsch wrote:
> I am trying to implode one column of a multidimensional array:
>  
> $array = array[]['name'];                   
> implode("string", $array[]['name']); 
>  
> Is there a simple function for extracting a single column of a
> multidimensional array other than using a foreach statement?

I'm not 100% clear on what you're looking to do, but this might be an
alternative to a foreach if your intention is to get the value of every
"name" for each index:

    $records =  array(
        array ('name'=>'foo', 'junk'=>'asdf'),
        array ('name'=>'bar', 'junk'=>'asdf'),
        );
    function get_name($array) { return $array['name']; }
    $names = implode(', ', array_map('get_name', $records));
    // $names is 'foo, bar'

HTH,
Andrew

-- 
Andrew Yochum
Plexpod
andrew at plexpod.com
718-360-0879



More information about the talk mailing list