How to "join" two numbers into one with PHP

I would like to join 2 numbers in to one number.

Example:

a=51
b=7543

now c = ab = 517543
d = ba = 754351

how can I join two numbers like shown above ?

Not sure if it’s the best solution, but here I go :slight_smile:


$a=51;
$b=7543 ;

$c = (int)($a . $b);
$d = (int)($b . $a);

Couldn’t you just do

$a = 51;
$b = 7543;

$c = $a . $b;
$d = $b . $a;

and retain them as numbers?

Sure and don’t forget about PHP loose type juggling as this would work too. And yes afterwards you can still perform mathematical functions on them


$a = 51;
$b = 7543;

$c = "$a$b";
$d = "$b$a";