Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. <?php
  2. /*
  3. Output a list of numbers multiple times depending on their value (e.g. output 9 nine times, or 18 eighteen times). Works well if it doesn't matter if you listall the numbers preceding the last number
  4. */
  5. $array = array(1,2,3,4,5,6,7,8,9,12,18);
  6.  
  7. foreach ($array as $num) {
  8. $string = '';
  9. $count = 1 * $num;
  10. for ($i=0;$i < $count; $i++) {
  11. $string .= (string)$num;
  12. }
  13.  
  14. echo $string.PHP_EOL;
  15. }
  16.  
  17. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement