Answer the question
In order to leave comments, you need to log in
How to gracefully and quickly display a number in a "bar" (ASCII bar graph)?
A certain function generates a set of numbers from 1..6. It is
necessary to visualize the output as a set of horizontal "stripes" written with symbols , something like this
XXX___
XX____
XXXXX_
XXX___
for ( $i = 1; $i<= N; $i++) { for ($j=1; $j<= set[$i]; $j++) { echo 'X'; } echo '<br/> '; }
Answer the question
In order to leave comments, you need to log in
Basically I found the solution :)
$str = str_repeat('_', MAX_STRING_LENGTH); // в данном случае 6
...
$bar = substr_replace($str, str_repeat('X', $i), 0, $i );
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question