0

I am making a website, so when you register, it sends you a confirmation email with a code. I have used this before, and I am wondering how to do this. I have four 1-9 random numbers, and I am wondering just how to join the numbers together to make a single one, or, if this isn't the proper way to do this, I would love to hear your thoughts.

Example

2 + 2 + 2 + 2 is 2222

Thanks to all of you who solved my question. Concatenation. I am an idiot.

whoff
  • 154
  • 13

2 Answers2

0

This can be done in many way like using . or , and so on. But I prefer with simple concatenation using . See more about concatenation at official site http://php.net/manual/en/language.operators.string.php

$n1= 2;
$n2= 2;
$n3= 2;
$n4= 2;
echo $n1.$n2.$n3.$n4;

Program Output

2222

DEMO: https://eval.in/981727

A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103
-2

I don't have an instance to test with but you could probably cast to string before using the add operator.

(string)2 + (string)2

If I am thinking correctly that should give you "22".

Edit: I was wrong and "+" is not interchangeable with string concatenation in PHP. the "." operator would be the correct one to use instead and would not require explicitly casting to string.

T0t3sMcG0t3s
  • 310
  • 1
  • 8