mardi 3 mars 2020

PHP: Get value on basis of probability

I have below array

$a = [
 'c1' => '10',
 'c2' => '20',
 'c3' => '10.50',
 'c4' => '19.99'
];

c1, c2, c3, c4 is Value we need on basis of probability 10, 20, 10.50, 19.99 .

So may be need to use rand() or mt_rand() function, so each time on basis of probability it gives random value from array.

Output can be c2 at 1st time, second time c4, third time may be c2 again

How to achieve this?




Aucun commentaire:

Enregistrer un commentaire