You are here: Re: happy new year with a simpleton question... « All PHP « IT news, forums, messages
Re: happy new year with a simpleton question...

Posted by Daemon on 01/01/06 13:16

Michael wrote:
> Ok, first of all I think you are going about this the wrong way. First
> of all I think we should put the names of the pictures into an array,
> so mine will be car.jpg, cat.gif and cow.png.
>
> [code]
> <?php
> $picture_array = array("car.jpg","cat.gif","cow.png");
> ?>
> [/code]
>
> Ok so now the script knows the names of the files we may display. We
> need to make the script generate a random number now and put it into a
> variable. So.....
>
> [code]
> <?php
> $picture_array = array("car.jpg","cat.gif","cow.png");
> $rand_no = rand(0,3);
> ?>
> [/code]
>
> Finally the script must render its data into (X)HTML. So...
>
> [code]
> <?php
> $picture_array = array("car.jpg","cat.gif","cow.png");
> $rand_no = rand(0,3);
> echo "<img src=\"".$picture_array[$rand_no]."\" />";
> ?>
> [/code]
>

You also can use another method and that is not to limit your self the
defined array, instead you can create the array by using glob, for the
existing files, and simpy using count to return the value of items in
your existing array.

<?php
$picture_array = glob("*.*");
$rand_no = rand(0,"count($picture_array)");
echo "<img src=\"".$picture_array[$rand_no]."\" />";
?>

~ Daemon

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация