PHP str_pad 打印字符串模式
str_pad :
用另一个字符串将一个字符串填充到一定长度。
Syntax:- str_pad (input, pad_length, pad_string_value, pad_type)
It returns the padded string.
参数说明
input:-The input string.
pad_length:-If the value of pad_length is negative, less than, or equal to the length of the input string, no padding takes place, and input is returned.
pad_string_input:-The pad_string may be truncated if the required number of padding characters can’t be evenly divided by the pad_string’s length.
pad_type:-Optional argument pad_type can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.
使用循环下的单行代码打印如下所示的简单模式。
例子:
Input : 5
Output :
*
**
***
****
*****
Input : 6
Output :
*
**
***
****
*****
******
输出:
*
**
***
****
*****
******