PHP Array function to return random integers -
i new php , trying create function generates , returns sorted array containing 6 random numbers , printing this. code have far follows:
function getrow($ball){ $ball = array(); for($i=1;$i<=6;$i++){ return $ball; } sort($ball); } echo '<pre>'; print_r(getrow(rand(1,59))); echo '</pre>';
the problem have no idea why printing 1 random number array. can me why or going wrong, if going wrong?
try instead, there many issues original code
$ball = []; for($i=1;$i<=6;$i++){ $ball[] = rand(1,59); } sort($ball); echo '<pre>'; print_r($ball); echo '</pre>';
result
array ( [0] => 3 [1] => 16 [2] => 20 [3] => 32 [4] => 39 [5] => 51 )
or, using function
function getrow() { $ball = []; for($i=1;$i<=6;$i++){ $ball[] = rand(1,59); } sort($ball); return $ball; } echo '<pre>'; print_r(getrow()); echo '</pre>';
Comments
Post a Comment