多维数组中的随机值

时间:2012-05-07 01:13:27

标签: php multidimensional-array

我如何在下面的代码中获得随机商品的价格并按照收音机插入mysql,如果有4个底子则选择:

$class1 = array("Peugeot 404"=>5000,"Opel Diplomat"=>7500,"Honda Civic"=>10000,"Renault Megane"=>15000);
$class2 = array("Ford Mustang"=>22500,"Dodge Charger"=>36000,"Alfa GTV "=>90000,"Aston Martin Vanquish"=>102000);
$class3 = array("BMW 7 series"=>114000,"Ferrari F430"=>132000,"Pagani Zonda"=>150000,"Maserati Gran Turismo"=>168000);
$class4 = array("Bentley Continental R"=>180000,"Maybach"=>200000,"Rolls-Royce Phantom"=>300000);

$rand1 = array_rand($class1,4);
$rand2 = array_rand($class2,4);
$rand3 = array_rand($class3,4);
$rand4 = array_rand($class4,3);

if($_POST['do'])
{
    echo $_POST['car'];
}
?>
<form method="POST">
<input type="radio" name="car" id="<? $rand1 ?>" value="<? echo "You have won: ".$rand1[0]." AND Price: ".$class1[$rand1[0]].""; ?>" />Class 1<br />
<input type="radio" name="car" id="<? $rand2 ?>" value="<? echo "You have won: ".$rand2[0]." AND Price: ".$class2[$rand2[0]].""; ?>" />Class 2<br />
<input type="radio" name="car" id="<? $rand3 ?>" value="<? echo "You have won: ".$rand3[0]." AND Price: ".$class3[$rand3[0]].""; ?>" />Class 3<br />
<input type="radio" name="car" id="<? $rand4 ?>" value="<? echo "You have won: ".$rand4[0]." AND Price: ".$class4[$rand4[0]].""; ?>" />Class 4<br />
<input type="submit" name="do" value="DO" />
</form> 
它就像一个黑手党游戏,当我选择第一个收音机时,我得到一个价格随机的汽车。而第二个按钮也给了我一个随机车的项目,但其他车型。

之后我需要将它插入到mysql DB中。

0 个答案:

没有答案