Specifications

Because the code selects random pictures, it produces a different page nearly every time you
load it, as shown in Figure 3.5.
Using PHP
P
ART I
84
FIGURE 3.5
The shuffle() function enables us to feature three randomly chosen products.
Using array_reverse()
The function array_reverse() takes an array and creates a new one with the same contents in
reverse order. For example, there are a number of ways to create an array containing a count-
down from ten to one.
Because using
range() alone creates an ascending sequence, we must then use rsort() to sort
the numbers into descending order. Alternatively, we could create the array one element at a
time by writing a
for loop:
$numbers = array();
for($i=10; $i>0; $i--)
array_push( $numbers, $i );
A for() loop can go in descending order like this. We set the starting value high, and at the
end of each loop use the -- operator to decrease the counter by one.
We created an empty array, and then used array_push() for each element to add one new ele-
ment to the end of an array. As a side note, the opposite of array_push() is array_pop(). This
function removes and returns one element from the end of an array.
05 7842 CH03 3/6/01 3:42 PM Page 84