Jump to content

Recommended Posts

This should be simple -- I am BRAND NEW to PHP...

I have this code...

foreach ($result as $value) {

echo trim($value)."+";


this currently works as it should and let's say the input is hello -- the web output is "hello+helloa+hellob+helloc" as it should be (using the other code in the program before this...  But..  I need to make it the variable so that a variable such as $car = "hello+helloa+hellob+helloc"...

When I simply replace echo trim($value)."+"; with $car = trim($value)."+"; it keeps REPLACING the variable each time and not adding it onto the end.  ANy help would be greatly appreciated.
Link to comment
https://forums.phpfreaks.com/topic/19280-making-variable-not-echo/
Share on other sites

Use $car .= trim($value) . "+"

.= adds whats on the right to the end of whats on the left. It'll produce waht you want.

For example:
[code=php:0]$foo = 'hello';

// We for got world so we add it in:

$foo .= " world";

//$foo now holds "hello world";[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.