We have
$symb="_"; $num=10;
We want it to $ten_symbsbe exactly. "__________"; // ten symbols "_". What is the fastest and / or best way to assign ten "_" to $ten_symbs?
$ten_symbs
"__________"; // ten symbols "_".
str_repeat () :
$symbol = '_'; $num = 10; echo str_repeat($symbol, $num);
You can use str_repeat like:
$ten_symbs = str_repeat($symb, $num);
You can also do:
$ten_symbs = str_pad('',$num,$symb);
But the fist parameter is cleaner.
find str_repeat () here: http://www.php.net/manual/de/function.str-repeat.php
$ten_symbs = ''; for($i=0;$i<$num;$i++) { $ten_symbs .= $symb; }