魏长东

weichangdong

东邪

php高亮

<?php
$pics = array(
array('weight'=>10,'value'=>'006.jpg','id'=>1),
array('weight'=>20,'value'=>'002.jpg','id'=>2),
array('weight'=>30,'value'=>'003.jpg','id'=>3),
array('weight'=>40,'value'=>'004.jpg','id'=>4),
array('weight'=>50,'value'=>'005.jpg','id'=>5),
array('weight'=>100,'value'=>'001.jpg','id'=>6),
);
$rand=mt_rand(1,100);
$price=array('weight'=>100,'value'=>'001.jpg',);
sort($pics);
foreach ($pics as $pic){
 $v=$pic['weight'];
 if ($rand<=$v) {
  $price=$pic;
  break;
 }
}
echo $price['value'];
?>