Jump to content

Breaking down the number 20 into echo "2"; echo "0";


slyte33

Recommended Posts

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 :)

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.