I need to place text in an array based on the content in the array. For example
<?php $stuff = array (5, 15, 50, 55, 90);
for ($i=0; $i<5; $i++) {
echo "<div style=position:absolute; top:$i"."px> $stuff[$i] </div>";
}
will output
5
15
50
55
90
Which is what I want, however the issue is the elements in the array may be close together, like 51 instead of 55 instead:
$stuff = array (5,15,50,51,90);
which would output
5
15
overlapping 50
and 51 here
90
since the font size of the text is larger than a single pixel.
Is there a way to position the elements as close to their natural spot without overlapping -- in the example 50 would go up just a hair and 51 would go down just a hair so they dont overlap.
Do something like this:
This checks the distance with all previous values.