我试图随机化一组来自数据库的结果,
这是数组的基础:
array (size=30)
0 => string '1' (length=1)
1 => string 'jordan' (length=6)
2 => string 'chris' (length=5)
3 => string '1' (length=1)
4 => string '1' (length=1)
5 => string 'card1, card2, card3, card4, card5, card6, card7, card8' (length=54)
6 => string 'card16, card20, card30, card40, card50, card60, card70, card80' (length=62)
7 => string '' (length=0)
8 => string '' (length=0)
9 => string '' (length=0)
10 => string '' (length=0)
11 => string '' (length=0)
12 => string '' (length=0)
13 => string '' (length=0)
14 => string '' (length=0)
15 => string '' (length=0)
16 => string '' (length=0)
17 => string '' (length=0)
18 => string '' (length=0)
19 => string '' (length=0)
20 => string '' (length=0)
21 => string '' (length=0)
22 => string '' (length=0)
23 => string '' (length=0)
24 => string '' (length=0)
25 => string '' (length=0)
26 => string '' (length=0)
27 => string '2013-11-21 04:23:19' (length=19)
28 => string '0' (length=1)
29 => string '0' (length=1)
我想从数组[5]中提取数据并将其随机化/随机化
while ($row = mysql_fetch_array($cards, MYSQL_NUM)) {
var_dump($row);
var_dump(array_rand($row[6], 2 ));
}
我已经尝试了各种各样的事情,现在我只是处于困惑的阶段,甚至比我刚开始时做的更多,有人可以帮助我吗?
答案 0 :(得分:0)
首先爆炸你的字符串:
$cards = explode(",", $row[6]);
然后,使用shuffle
进行随机化,然后使用内爆:
shuffle($cards);
$result = implode(",", $cards);
它现在应该是一个洗牌清单。
答案 1 :(得分:0)
您可以使用php函数shuffle以便在数组中随机化。 然后你只需要将你想要的数据拉到一个数组,随机播放它然后显示它:)
答案 2 :(得分:0)
试试这个
function getR($ipt)
{
$pieces = explode(",", $ipt);
return $pieces[mt_rand(0,count($pieces)-1)];
}
while ($row = mysql_fetch_array($cards, MYSQL_NUM))
{
echo getR($row[5]);
}