I have this code <? // Random photo $photo = array ('images/Clipboard11.jpg ', 'images/Clipboard12.jpg'); counti= (count($photo) -1 ); $foto = rand(0,$count); print "<img scr = $foto width = '150' height = '157'>"; ?> Code (markup): No errors, but don't show any photo. Link to the photo is true correctly. ( Sorry for mistakes, i am not good in english )
<?php // Random photo $photo = array ('images/Clipboard11.jpg', 'images/Clipboard12.jpg'); $count = (count($photo) -1 ); $foto = rand(0,$count); print "<img src = \"" . $photo[$foto] . "\" width = '150' height = '157'>"; ?> Code (markup): Above is the corrected code, you missed a $ off of count and also called one variable counti but never used it. Within the line that builds the image you didn't reference the array element but simply output the index of the element you wanted.
You should use array_rand() so you can skip counting your the size of your array. Also if you had only $array[0] and $array[2] defined, what would happen with yours if it picked $array[1]? (I know chances are this won't happen with this particular script, but it can with others) http://us3.php.net/manual/en/function.array-rand.php <?php // Random photo $photo = array ('images/Clipboard11.jpg', 'images/Clipboard12.jpg'); //** You can get rid of this $count = (count($photo) -1 ); $foto = array_rand($photo): print "<img src = \"" . $photo[$foto] . "\" width = '150' height = '157'>"; ?> Code (markup): -the mole