Okay, I'm really struggling with this one. I need to check if a string is a "valid lottery sequence". I don't want it to alter the string to make it right, I want to know if an inputted string is already right (true/false). Rules:
1. there must be six numbers made up of two digits.
2. each number must be 49 or under.
3. each number must be unique.
4. the numbers must be in numerical order.
For example:
01, 02, 03, 04, 05, 06 = okay!
02, 01, 03, 04, 05, 06 = nope
01, 01, 03, 04, 05, 06 = nope
01, 02, 03, 04, 05, 51 = nope
01, 02, 03, 04 = nope
1, 2, 03, 04, 05, 06 = nope
01, 02, 03, 04, 05, 06, 07 = nope
But my PHP knowledge is pretty basic. Therefore I'd end up doing things like exploding the string and checking each number using:
preg_match /01|02|03| ... up to 48|49/
to check it is 49 or less. Which is quite a long way to do it for each number. Surely there is a quicker way to check each number is between 1-49?
Also, I know how to sort($numbers); into a sequence, but is there a way to check they are already sorted? Or would I have to sort($numbers); the string, then see if it matches the original using preg_match again?
Lastly, I'm reading up on array_unique() and array_count_values() to cover the requirement of six numbers and them being unique - but squeezing that into a couple of lines (and attempting to include a "two digit" checker) is proving difficult.
I'm hoping that some genius here will be laughing at my childish understanding of PHP whilst reading this, and will be able to spit out an easy, short way to do this in a matter of seconds!
Well? ..... ;)