Jump to content

[SOLVED] Why doesn't this code work??


nicob

Recommended Posts

:-[

 

I have a list with 1000 tips and I want to show only 10 lines at a time. As I don't want to show the same 10 lines, I shuffle the list. But my code is not working :-[

 

<?php

$file = file_get_contents('tips.txt');
$data = explode("",$file);

shuffle($data);
$newfile = implode("",$data);

echo implode("",array_slice(file("$newfile"),0,10));

?>

Link to comment
https://forums.phpfreaks.com/topic/134685-solved-why-doesnt-this-code-work/
Share on other sites

@Mchl

I was using that code to split strings, but I have removed this in my new code.

 

@Mark

I made this. It shows 10 lines, BUT shuffle is not working. Maybe now I'm going the wrong direction... ::)

 

<?php
$file = file('tips.txt');
shuffle($file);
echo implode("",array_slice(file('tips.txt'),-10,10));
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.