taylhis Posted August 31, 2006 Share Posted August 31, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19280-making-variable-not-echo/ Share on other sites More sharing options...
wildteen88 Posted August 31, 2006 Share Posted August 31, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/19280-making-variable-not-echo/#findComment-83618 Share on other sites More sharing options...
HeyRay2 Posted August 31, 2006 Share Posted August 31, 2006 [code]<?php$car .= trim($value) . "+"?>[/code]is going to add an extra "[b]+[/b]" to the end of the string. Try this:[code]<?phpforeach( $result as $value ){ // trim each array item $value = trim($value);}$car = implode('+', $result);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/19280-making-variable-not-echo/#findComment-83630 Share on other sites More sharing options...
taylhis Posted August 31, 2006 Author Share Posted August 31, 2006 You guys rock! WORKS! Quote Link to comment https://forums.phpfreaks.com/topic/19280-making-variable-not-echo/#findComment-83667 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.