topical media & game development

talk show tell print

mashup-flickr-03-exercises-3-1.php / php



  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <link href="../css/main.css" rel="stylesheet" type="text/css" />
    <title>Flickr Mashups</title>
  </head>
  <body>
    <h1>Exercise 3-1</h1>
    <?php
    
    // Create an array of 1000 numbers
    
    numbers = array();
    
    for (i = 0; i < 1000; i++)
    {
      array_push(numbers, rand(1, 1000));  
    }
    
    ?>
    
    <p>Array of <?php echo count(numbers) ?> numbers created.</p>
    
    <?php
    
    total = 0;
    foreach (numbers as n)
    {
      total += n;
    }
    
    average = total / count(numbers);
    
    ?>
    <p>The average is <?php echo average ?></p>
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.