Forum Moderators: coopster
a script will be called, and then one line of data from a csv file will be printed ( echo command), the code works fine, but the thing is every time the code is called the first line of data is printed out, I want to change that to random, because the csv file contains lots of data (one on every line seperaged by %%)that has to be printed, the way it works now, it only prints same data each time,( first line of data).
I have tried the shuffle function as well, but i could not make it work, I just replace the this line ( $data = explode('%%', $data); )
with this one ($data = shuffle(explode('%%', $data));)
but stoped to print,
anyone willing to help?
Here is the code :
$count = $oldcount = $totalcount = $tally = 0;
$data = file_get_contents("data.csv");
$data = explode('%%', $data);
$di = 0;
$printme .= "\n" . $data[$di++];
if($di>=count($data))$di=0;
$tally = 0;
}
}
$totalcount += $count;
}
}
echo $printme;
}
?>
thanks.
shuffle() [php.net] returns a boolean value, not one of the "shuffled" index values.
bool shuffle ( array &$array )
I'm guessing you realized that and found that you needed to grab an index value after shuffling the array. Again, glad you got is sorted, I just wanted to post a possible answer here for future readers!