what is the effect of the function str_pad()
to strings?
please explain to me because I cant understand its definition from w3schools. Thanks.
It pads a string to a certain length with (optional) another string.
For example
$foo = 'hello world'; // length 11
echo str_pad($foo, 13); // will echo 'hello world ';
You can also add a string for padding
$foo = 'hello world';
echo str_pad($foo, 13, 'x'); // will echo 'hello worldxx';
Moreover you can specify where you want the string to be padded
$foo = 'hello world';
echo str_pad($foo, 13, 'x', STR_PAD_LEFT); // will echo 'xxhello world';
$foo = 'hello world';
echo str_pad($foo, 15, 'x', STR_PAD_BOTH); // will echo 'xxhello world';
However, never use w3schools for PHP but try to understand it directly from PHP documentation