...

View Full Version : How can I split a 6 digit number in to 2 separate numbers?



spyros
07-22-2007, 10:01 AM
Hello
I have a 6 digit number and I want to split it to 2 separate numbers do you know how can I do this ?
For example the number 200509 I want to split it in to 2005 and 09.

Thank you.

GJay
07-22-2007, 11:17 AM
like this:


list($year,$month) = str_split(200709,4);


Basically, you're wanting to treat the number as a string (which PHP will do for you) and split it after the 4th character, giving a 4-character 'chunk' and a 2-character one. str_split returns an array, so using list() lets you assign the values directly to variables.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum