Home > Article > Backend Development > How to align information output in php
How to align information output in php
1. Left alignment
printf(“%d\n”,101010);
The default is left alignment.
printf(“%-10d\n”,101010);
"-" means left alignment, just add "-" in front of the number width.
Note: The number width is 10. If the number of digits to be printed is less than 10, spaces will be added at the end; if the number of digits to be printed is greater than 10, all numbers will be printed without truncation.
2. Right alignment
printf(“%10d”,101010);
Add a numerical width between % and d to right align.
Instructions: The number width is 10. If the number of digits to be printed is less than 10, add spaces on the left; if the number of digits to be printed is greater than 10, all numbers will be printed without truncation.
e.g
Output the name (10 characters wide, left-justified), the number of questions done (2 characters wide, right-justified) and the time (4 characters wide, right-justified) ).
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to align information output in php. For more information, please follow other related articles on the PHP Chinese website!