Jump to content

Generating statistics from array output


keegan90

Recommended Posts

Hi there, first post so hope it goes well :)

 

Im trying to generate statistics on which quote will be displayed each time i refresh the page.

 

I've stored 10 famous quotes in the $famous_quotes array but have no idea on how to find out which 1 has been selected and then to generate the stats for that quote (if its even possible!!!)

 

Have been stuck on this problem for 4 days now!! So any help would be appreciated.

 

This is the code used for storing and randomising my quotes.

 

 

<?php

$famous_quotes=array("Imagination is more important than knowledge - Albert Einstein", 

"If music be the food of love, play on - Shakespeare", 

"Never let your sense of morals get in the way of doing what's right - Isaac Asimov",

"Obstacles are those frightful things you see when you take your eyes off the goal - Henry Ford",

"When you come to a fork in the road, take it - Yogi Berra",

"We may affirm absolutely that nothing great in the world has been accomplished without passion - Hegel",

"The life which is unexamined is not worth living - Socrates",

"Live as if you were to die tomorrow. Learn as if you were to live forever - M.K. Gandhi",

"What you get by achieving your goals is not as important as what you become by achieving your goals - Zig Ziglar",

"A lie gets halfway around the world before the truth has a chance to get its pants on - Sir Winston Churchill");

 

print_r($famous_quotes);

 

 

$random = rand(0, 9); 

 

 

echo $famous_quotes[$random];

 

?>

 

 

Have tried things like

 

<?php

if ($random = 1)

{

    $a = 0;

    $a++;

}

if ($random = 2)

{

$b = 0;

$b++;

}

  ?>

to try store which quote its printing out and then create stats using $a for first quote, $b for second etc etc...

 

But nothing works!!!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.