Link to home
Start Free TrialLog in
Avatar of areyouready344
areyouready344Flag for United States of America

asked on

how to unsort output text lines from a sorted input in php?

The following code below reads sorted text lines from a file, around 30 lines and output them in sorted lines on the computer screen. But what I would like is to output the input sorted text lines unsorted without repeating the same text lines..


while(!feof($file))
{
$myfilevalue = fgets($file);
               echo '<font size="6" color="' . random_color() . '">' . $myfilevalue . '</font>';
}

function random_color()
{
    mt_srand((double)microtime()*1000000);
    $c = '';
    while(strlen($c)<6)
    {
        $c .= sprintf("%02X", mt_rand(0, 255));
    }
    return $c;
}
fclose($file);
?>
</body>
</html>
 
ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of areyouready344

ASKER

thanks Marqus, also, if i wanted to display ten lines instead of all 20 lines from the shuffle, i would do this..

$display_ten_lines = 10;
$count_0 = 0;

while(!feof($file))
{
$myfilevalue[] = fgets($file);
}

if (shuffle($myfileValue)){
  foreach ($myfileValue as $v){
   if($count_0 < $display_ten_lines)
  {
    echo '<font size="6" color="' . random_color() . '">' . $v . '</font>';
    $count_0++  
}  
}
}
Awesome! Thanks for points.
Cheers