Jexon Jexon - 1 year ago 62
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".


Answer Source

Using str_split. You can divide in half.

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

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