mercredi 22 juillet 2015

How to get a non-random value from a randomly selected value?

I am trying to select a non-random value for a random selected value. As seen below. The first column is to represent the sale number (1-30), the second column is to show the item which must be selected at random, and the third column is to show the corresponding price for said item. How can I achieve this given that the item is selected at random?

I had thought of using a switch statement but thought that this might get messy and there is probably a better way of doing so?

$items = array( ‘clock’ , ‘kettle’ , ‘mug’ , ‘toaster’ , ‘CD’);


for($i = 0; $i < 30; $i++) {
$sales[$i][0] = $i + 1; //Starts at 1 and increments
$sales[$i][1] =  $items[rand(0,4)]; //Item chosen at random
$sales[$i][2] = //Should be the corresponding price for the above item.
}




Aucun commentaire:

Enregistrer un commentaire