Random function in image
In this code simpl use of random function and switch case.First of all random function call in switch case and pass the initial and final value of case such as no of cases =16( 1 to 16 ) then first orgument is 1 and second orgument is 16 and seprated by comma.Then starting a switch case curly braces and then start the first case,make a variable which store the the image same as all cases and assign the image and then use break keyword (break is used for stop a particular case ,if you don't use break all the case excuted and all the values ).Lastly print the variable which store the image using html img embed tag.Check this code in your browser .
<?php
Download PHP PDF php basic tutorial pdf
echo "Making by umar farooque khan";
switch(rand(1,16))
{
case 1:
$greet ="1.jpg";
break;
case 2:
$greet ="2.jpg";
break;
case 3:
$greet ="3.jpg";
break;
case 4:
$greet ="4.jpg";
break;
case 5:
$greet ="a(1).jpg";
break;
case 6:
$greet ="a(2).jpg";
break;
case 7:
$greet ="a(3).jpg";
break;
case 8:
$greet ="a(4).jpg";
break;
case 9:
$greet ="a(5).jpg";
break;
case 10:
$greet ="a(6).jpg";
break;
case 11:
$greet ="a(7).jpg";
break;
case 12:
$greet ="a(8).jpg";
break;
case 13:
$greet ="a(9).jpg";
break;
case 14:
$greet ="a(10).jpg";
break;
case 15:
$greet ="a(11).jpg";
break;
case 16:
$greet ="a(12).jpg";
break;
}
echo"<img src='$greet' height='900px' width='1200px'>";
?>
For more on php visit php-tutorial
No comments:
Post a Comment