[nycphp-talk] Implode a column of a multi-dim array
Cliff Hirsch
cliff at pinestream.com
Wed Oct 26 12:49:12 EDT 2005
Interesting solution. array_map with a callback makes my head spin a
bit! I'll try to benchmark this solution versus foreach to see which is
faster and will report back.
-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org]
On Behalf Of Andrew Yochum
Sent: Wednesday, October 26, 2005 12:00 PM
To: NYPHP Talk
Subject: Re: [nycphp-talk] Implode a column of a multi-dim array
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
_______________________________________________
New York PHP Talk Mailing List
AMP Technology
Supporting Apache, MySQL and PHP
http://lists.nyphp.org/mailman/listinfo/talk
http://www.nyphp.org
More information about the talk
mailing list