Jump to content

Making variable not echo...


taylhis

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
Share on other sites

[code]
<?php

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

?>
[/code]

is going to add an extra "[b]+[/b]" to the end of the string. Try this:

[code]
<?php

foreach( $result as $value ){
   // trim each array item
   $value = trim($value);
}

$car = implode('+', $result);

?>
[/code]
Link to comment
Share on other sites

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.