Jexon Jexon - 6 months ago 12
PHP Question

Split 4 digit number into 2 variables in PHP

Using PHP...

If I have a number, for example, 0901, how can I then get 2 separate variables?

The first containing "09" and the second "01".

Thanks!

Answer

Using str_split. You can divide in half.

$number = "0901";
$arr = str_split($number, strlen($number)/2);

print $arr[0];
print $arr[1];
Comments