My answer to this will be in two parts. First of all, finding out is a number is odd or even:
PHP Code:
<?php
function isEven($n) {
if ($n % 2) {
return true;
} else {
return false;
}
}
?>
The second is to do with the question. I'd run it as an array or collection of quotation objects:
PHP Code:
<?php
class Quotation {
private $author;
private $quote;
function __construct($author, $quote) {
$this->author = $author;
$this->quote = $quote;
}
public function Author {
return $this->author;
}
public function Quote{
return $this->quote;
}
}
$quotations = array(
new Quotation("Albert Einstein", "Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."),
new Quotation("Bill Gates", "The Internet is becoming the town square for the global village of tomorrow."),
new Quotation("Gandalf", "Use the force, Harry!"),
new Quotation("Unkown Author", "No-one knows who wrote this quote but the author."),
);
$rndIndex= rand(0, (count($quotations) -1));
?>
Usage:
PHP Code:
<?php foreach ($quotations as $quotation) { ?>
<blockquote class="quotation">
<?php echo $quotation->Quote; ?>
<span id="author">
<?php echo $quotation->Author; ?>
</span>
</blockquote>
<?php } ?>
Or for a random quote:
PHP Code:
<blockquote class="quotation">
<?php echo $quotations[$rndIndex]->Quote; ?>
<span id="author">
<?php echo $quotations[$rndIndex]->Author; ?>
</span>
</blockquote>
Bookmarks