Please explain me how the rand function is working here... code is below


	// Create an array and push on the names
	$players = array();
    // of your closest family and friends
	// Sort the list
	$maxCount = count($players);?><br><?php
	// Randomly select a winner!
	$winner = $players[rand(0,$maxCount-1)];
     echo strtoupper($winner);


randint is a built in function which generates a random integer, between zero length of array minus one to randomly select a player from your array


randint is built in function ok its generate a random no between zero to lenth of array ok but minus one not understand
plz help once.


we humans start counting at 1, so does count()

but arrays are zero indexes based, this is why we subtract one, to compensate for this difference


Hey stetim94 Thanks you make my day !


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.