arrays
Posted: Mon Jun 26, 2006 4:03 pm
I found this random image script - that makes use of arrays.
php.net's explanation or arrays was very confusing - so I was wondering if someone could simplify it for me. From what I can tell - the above array is assigned the name $quote. I imagine that each number, 1-5 - holds a line of text. Great. What I want to know - is syntax. Could someone please explain to me the syntax of this, and other arrays in php?
(also, I know that the rand() function calls a random number - and srand() seeds it, but could someone explain the correct implementation of rand()/srand() in php for me as well?)
Code: Select all
<?php
$quote = array(
1 => "<img src='image1.jpg'>",
2 => "<img src='image2.jpg'>",
3 => "<img src='image3.jpg'>",
4 => "<img src='image4.jpg'>",
5 => "<img src='image5.jpg'>",
);
srand ((double) microtime() * 1000000);
$randnum = rand(1,5);
echo"$quote[$randnum]";
?>(also, I know that the rand() function calls a random number - and srand() seeds it, but could someone explain the correct implementation of rand()/srand() in php for me as well?)