2017-08-19 95 views
0

我有这样的代码:洗牌内爆阵列(HTML复选框到数组)

HTML复选框名称:

name="selection[]" 

代码:

$selections = $_POST['selection']; 

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

这仅仅是预览输出,然后:

$selectionsfull = implode(PHP_EOL, $selections); 

我是wri使用fpopen文件:

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

但我似乎无法使输出洗牌。我已经尝试过10种不同的洗牌方法,但无法使用它。你可以洗牌爆裂阵列吗?我也尝试过首先爆炸,但每次都出错。

谢谢!

回答

0

好吧,我愚蠢......

shuffle($selections); 

$selectionsfull = implode(PHP_EOL, $selections); 

echo $selectionsfull; 

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

作品。

0

implode函数只是返回一个不能混洗的字符串。看起来你应该能够在爆炸之前洗牌,除非我错过了一些东西。你不需要运行爆炸,因为你已经有一个数组开始。

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

在我看到这篇文章之前,我完全明白了。感谢您的回应,意识到我在这里犯了一个非常新手的错误。再次感谢! – Joe

+0

这个答案不正确。 – mickmackusa

+0

你能否给出一个解释,为什么你认为它不正确? – Thursday42