a one liner, but I doubt you will get anything on performance cause of the
lambda function.

implode( ',', array_map( create_function('$a', 'return @$a["value"];'),
$temp ) );

On 26 April 2010 11:43, Wazzä <[email protected]> wrote:

> On  26/Apr/2010, at 11:31 , chris burgess wrote:
>
> > What's the tersest way to turn this -
> >
> >  $temp = array(
> >    array( 'value' => 'one', ),
> >    array( 'value' => 'two', ),
> >    array( 'value' => 'three' ),
> >  ) ;
> >
> > into this -
> >
> >  $str = 'one,two,three' ;
> >
> > I'm using
> >
> >        foreach ( $temp as $t ) {
> >          $t2[] = $t['value'] ;
> >        }
> >        $str = implode(',', $t2);
> >
> > ... but my brain is nagging me that there's a one-liner.
>
>
> Untested, but my brain says:
>
>       foreach ( $temp as $t )
>                $str .= sprintf("%s%s", (strlen($str))?", ":"",
> $t['value']);
>
> (This is knee jerk, YMMV and I've not tested it.)
>
> --
> NZ PHP Users Group: http://groups.google.com/group/nzphpug
> To post, send email to [email protected]
> To unsubscribe, send email to
> [email protected]<nzphpug%[email protected]>
>

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to