slyte33 Posted January 6, 2013 Share Posted January 6, 2013 Hello everyone! I cant seem to figure this out... here's a code for example: $number = "20"; echo "2"; echo "0"; If you're wondering why I need something like this it's because I'm making the number show in a php image, but instead of outputting numbers 0-99, I could split the number 20 into "2" and "0" to output only numbers 0-9 Any help would be greatly appreciated Quote Link to comment Share on other sites More sharing options...
us2rn4m2 Posted January 6, 2013 Share Posted January 6, 2013 Hello, $number = "20"; str_split($number); echo $number[0]; echo '<br />'; echo $number[1]; /* Result 2 0 */ Quote Link to comment Share on other sites More sharing options...
requinix Posted January 6, 2013 Share Posted January 6, 2013 If it's always (at least) two digits you can simply $number = "20"; echo $number[0]; echo $number[1]; Quote Link to comment Share on other sites More sharing options...
slyte33 Posted January 6, 2013 Author Share Posted January 6, 2013 Hello, $number = "20"; str_split($number); echo $number[0]; echo '<br />'; echo $number[1]; /* Result 2 0 */ If it's always (at least) two digits you can simply $number = "20"; echo $number[0]; echo $number[1]; Awesome, thanks both of you Quote Link to comment Share on other sites More sharing options...
us2rn4m2 Posted January 6, 2013 Share Posted January 6, 2013 // correction $number = "20"; $n = str_split($number); echo $n[0]; echo $n[1]; Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 7, 2013 Share Posted January 7, 2013 Example of the method shown by requinix, for a variable length number: $string = 3251; $max = strlen ($string); for ($run = 0; $run < $max; $run++) { echo $string[$run]."\n"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.