note 90555 added to function.str-repeat
| From: | DamienBezborodov at osu1 dot php dot net | Date: | Tue, 28 Apr 2009 07:45:19 +0000 |
| Subject: | note 90555 added to function.str-repeat | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153891@lists.php.net to get a copy of this message | ||
Here is a simple one liner to repeat a string multiple times with a separator:
<?php
implode($separator, array_fill(0, $multiplier, $input));
?>
Example script:
<?php
// How I like to repeat a string using standard PHP functions
$input = 'bar';
$multiplier = 5;
$separator = ',';
print implode($separator, array_fill(0, $multiplier, $input));
print "\n";
// Say, this comes in handy with count() on an array that we want to use in an
// SQL query such as 'WHERE foo IN (...)'
$args = array('1', '2', '3');
print implode(',', array_fill(0, count($args), '?'));
print "\n";
?>
Example Output:
bar,bar,bar,bar,bar
?,?,?
----
Server IP: 117.55.229.1
Probable Submitter: 210.10.53.49
----
Manual Page -- http://www.php.net/manual/en/function.str-repeat.php
Edit -- https://master.php.net/note/edit/90555
Del: integrated -- https://master.php.net/note/delete/90555/integrated
Del: useless -- https://master.php.net/note/delete/90555/useless
Del: bad code -- https://master.php.net/note/delete/90555/bad+code
Del: spam -- https://master.php.net/note/delete/90555/spam
Del: non-english -- https://master.php.net/note/delete/90555/non-english
Del: in docs -- https://master.php.net/note/delete/90555/in+docs
Del: other reasons-- https://master.php.net/note/delete/90555
Reject -- https://master.php.net/note/reject/90555
Search -- https://master.php.net/manage/user-notes.php