Shuffle imploded array(HTML复选框到数组中)

时间:2017-08-19 00:14:42

标签: php arrays explode shuffle implode

我有这段代码:

HTML复选框名称:

name="selection[]"

代码:

$selections = $_POST['selection'];

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

这只是为了预览输出,然后:

$selectionsfull = implode(PHP_EOL, $selections);

我正在使用fpopen写一个文件:

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

但我似乎无法让输出变得混乱。我尝试了10种不同的洗牌方法,但无法让它发挥作用。你可以洗掉一个内爆阵列吗?我也先试过爆炸,但每次都出错了。

谢谢!

2 个答案:

答案 0 :(得分:0)

implode函数只返回一个不能被洗牌的字符串。看起来你应该能够在爆炸之前将阵列洗牌,除非我遗漏了什么。您不需要运行爆炸,因为您已经有一个数组可以启动。

$selections = $_POST['selection'];
$selections = shuffle($selections);
$selectionsview = implode("<br>", $selections);

答案 1 :(得分:0)

好吧,我很蠢......

shuffle($selections);

$selectionsfull = implode(PHP_EOL, $selections);

echo $selectionsfull;

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

作品。

相关问题