Drezard Posted June 2, 2007 Share Posted June 2, 2007 So basically I have these numbers: $number1 = 5; $number2 = 25; $number3 = 50; And I want to add them on to the end of each other. So I tried to use code like this: $numbers = $number1 . $number2 . $number3; But that didn't work all it outputs is the last number. What other code could I use? Regards, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/53955-adding-to-a-string-or-number/ Share on other sites More sharing options...
ryeman98 Posted June 2, 2007 Share Posted June 2, 2007 I don't understand what you mean. I'll try to figure it out though. Here's what I've got: <?php $number1 = 5; $number2 = 25; $number3 = 50; $numbers = $number1 . $number2 . $number3; print $numbers; ?> Or do you mean to add them like: $number1 + $number2 + number3 = 80 Again, I don't completely understand what you mean so... yeah. Quote Link to comment https://forums.phpfreaks.com/topic/53955-adding-to-a-string-or-number/#findComment-266740 Share on other sites More sharing options...
Drezard Posted June 2, 2007 Author Share Posted June 2, 2007 so basically 5, 25 and 50 are examples normally it would be from a form. But I want it to output something like this.... if i used 5, 25 and 50: 52550 See how it is adding the number on to the end each time? how would I do that? Regards, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/53955-adding-to-a-string-or-number/#findComment-266742 Share on other sites More sharing options...
ryeman98 Posted June 2, 2007 Share Posted June 2, 2007 Uhh... echo "".$number1."".$number2."".$number3.""; :-\ Quote Link to comment https://forums.phpfreaks.com/topic/53955-adding-to-a-string-or-number/#findComment-266744 Share on other sites More sharing options...
wildteen88 Posted June 2, 2007 Share Posted June 2, 2007 Using this should work: echo $number1 . $number2 . $number3; Having to concat an empty string onto a number is waste of processing. Remove the "" and use just the concatenation operator. <?php $number1 = 5; $number2 = 21; $number3 = 88; $numbers = $number1 . $number2 . $number3; echo $numbers; ?> Output is 52188 Can't see how it doesn't work for you. How areyou echoing $numbers? Quote Link to comment https://forums.phpfreaks.com/topic/53955-adding-to-a-string-or-number/#findComment-266816 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.