Re: string concatenation from array
| From: | Analysis & Solutions | Date: | Tue, 12 Aug 2003 20:02:28 +0000 |
| Subject: | Re: string concatenation from array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-159323@lists.php.net to get a copy of this message | ||
On Tue, Aug 12, 2003 at 01:58:21PM -0600, Micah Montoy wrote:
> I'm having a bit of difficulty getting a string to attach to itself from an
> array. Here is the bit of code I'm working on.
>
A bunch of simplifications, efficiency tweaks on this approach...
> $wresult = "";
$wresult = '';
>
> foreach ($search_string as $word_result){
> $wresult = $wresult & " " & $word_result;
$wresult = $wresult . ' ' . $word_result;
OR you can do...
$wresult .= $word_result;
> }
>
> echo ("$wresult");
echo $wresult;
BUT, the far far far better way to do this just takes one line:
echo implode(' ', $search_string);
--Dan
--
FREE scripts that make web and database programming easier
http://www.analysisandsolutions.com/software/
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7th Ave #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409