-4

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!

Jexon
  • 23
  • 1
  • 7
  • 4
    There are multiple ways to solve this... but you go first: what have you tried? If the response to that is "I tried posting on stackoverflow", you have not done enough on your own yet. – mah Jun 03 '16 at 23:24
  • Is the length of the number always known ahead of time, even if it has leading zeroes? I.e., given `1`, the output would be `00` and `01`, and the number `10000` would never appear? Also, are these actual numbers (integers) or strings that just happen to contain numbers? – Kal Zekdor Jun 03 '16 at 23:28
  • Is it always 4 digits? What happens if it is 3 or 5, how would you split it? What code attempts have you tried? What php functions have you tried? ie [`array str_split ( string $string [, int $split_length = 1 ] )`](http://php.net/manual/en/function.str-split.php) – Sean Jun 03 '16 at 23:31

1 Answers1

1

Using str_split. You can divide in half.

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

print $arr[0];
print $arr[1];
user24100
  • 27
  • 1
  • 6