0

I have this code:

HTML checkbox names:

name="selection[]"

Code:

$selections = $_POST['selection'];

$selectionsview = implode("<br>", $selections);
echo $selectionsview;

This is just to preview the output, then:

$selectionsfull = implode(PHP_EOL, $selections);

I'm writing to a file using fpopen:

$fp = fopen('data.txt', 'w');
fwrite($fp, print_r($selectionsfull, TRUE));
fclose($fp);

But I can't seem to make the outputs shuffle. I've tried like 10 various methods of shuffling, but can't get it to work. Can you shuffle an imploded array? I also tried exploding first, but it errors out every time.

Thanks!

Joe
  • 143
  • 10

2 Answers2

0

The implode function just returns a string, which can't be shuffled. It seems like you should be able to shuffle the array before imploding, unless I'm missing something. You shouldn't need to run explode since you already have an array to start.

$selections = $_POST['selection'];
$selections = shuffle($selections);
$selectionsview = implode("<br>", $selections);
Thursday42
  • 197
  • 5
0

Okay I'm dumb...

shuffle($selections);

$selectionsfull = implode(PHP_EOL, $selections);

echo $selectionsfull;

$fp = fopen('data.txt', 'w');
fwrite($fp, print_r($selectionsfull, TRUE));
fclose($fp);

Works.

Joe
  • 143
  • 10