Jump to content

Adding to a string or number


Drezard

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

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.