How to convert an array to a number in PHP?

I want to convert an array to one large number in PHP.

For example, I have an array $ array:

$array[0] = 10;
$array[1] = 20;
$array[2] = 30;
$array[3] = 40;

I want this to be:

$one_large_number = 10203040;

I read somewhere a way to convert an array to a string, but that will not allow me to perform mathematical operations, right?

So, does anyone know how to convert an array to one continuous number?

Thank.

+3
source share
4 answers
join("", $array);

A bit more about this here: http://www.w3schools.com/php/func_string_join.asp

http://codepad.org/Dv0zdtaJ is a living example. As you can see, you can easily perform additional mathematical functions with this number :)

+1
source

implode() :

$array = array(10, 20, 30, 40);
$one_large_number = implode("", $array);
// Output: 10203040
+1

, implode it alias

$array[0] = 10;
$array[1] = 20;
$array[2] = 30;
$array[3] = 40;
$one_large_number = implode('',$array);
+1

, :

intval(implode('', $array));
+1

All Articles