john7911 Posted May 22, 2019 Share Posted May 22, 2019 Hi :-) How can I align digit as you can see in the screen shot. <?php function MaFonction($x){ for ($i=0 ; $i<=360 ; $i+=$x){ echo $i . " ==> " . deg2rad($i) . "<br />"; } } ?> <?php MaFonction(15 ); ?> Thank you ;-) Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 22, 2019 Share Posted May 22, 2019 (edited) function MaFonction($x){ for ($i=0 ; $i<=360 ; $i+=$x){ echo sprintf("%02d", $i) . " ==> " . deg2rad($i) . "<br />"; } } MaFonction(15 ); Edited May 22, 2019 by benanamen Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2019 Share Posted May 23, 2019 Use right-aligned text for ($i=0; $i<= 180; $i+=15) my_function($i); function my_function($d) { echo "<div style='width: 30px; display:inline-block; text-align:right'>$d</div> ==> " . deg2rad($d) . '<br>'; } Quote Link to comment Share on other sites More sharing options...
Barand Posted May 23, 2019 Share Posted May 23, 2019 Or you can use printf() (as Benanamen suggested) between <pre>..</pre> tags echo '<pre>'; for ($i=0; $i<= 180; $i+=15) my_function2($i); echo '</pre>'; function my_function2($d) { printf("%4d ==> %0.6f\n", $d, deg2rad($d)) ; } 0 ==> 0.000000 15 ==> 0.261799 30 ==> 0.523599 45 ==> 0.785398 60 ==> 1.047198 75 ==> 1.308997 90 ==> 1.570796 105 ==> 1.832596 120 ==> 2.094395 135 ==> 2.356194 150 ==> 2.617994 165 ==> 2.879793 180 ==> 3.141593 Quote Link to comment Share on other sites More sharing options...
john7911 Posted May 23, 2019 Author Share Posted May 23, 2019 Thank you very much for your help ? 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.