jeudi 30 mars 2017

PHP Array Select Random Value on Refresh

I have Submit button on Page. Once I click each time it should give random different result.

I have below array code

$qty = 10;
$array = array(4 => 2, 6 => 5, 7 => 10, 8 => 1, 10 => 5);
$array = arsort($array);
echo "<pre>";
print_r($array);
//array_rand($array);
exit;

Array pair is Customer & It's Quantity. I need to compare $qty with array's highest value. If it matches then take that value out & print out final result.

It is not necessary to assign 100% qty to each customer. But in the end 10 qty should assign overall.

So output can be

1st Click on Submit Button

Array
(
    [7] => 10
)

2nd Click on Submit Button

Array
(
    [7] => 2
    [6] => 2
    [10] => 2
    [4] => 2
    [8] => 2
)

3rd Click on Submit Button

Array
(
    [7] => 5
    [6] => 2
    [10] => 3
)




Aucun commentaire:

Enregistrer un commentaire