Home > Backend Development > PHP Problem > How to align information output in php

How to align information output in php

angryTom
Release: 2023-02-27 21:20:01
Original
5623 people have browsed it

How to align information output in php

How to align information output in php

1. Left alignment

printf(“%d\n”,101010);
Copy after login

The default is left alignment.

printf(“%-10d\n”,101010);
Copy after login

"-" 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);
Copy after login

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

How to align information output in php

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template