Welcome Guest, Not a member yet? Register   Sign In
array
#5

[eluser]bretticus[/eluser]
I think perhaps you need an array or arrays. In other words, you can put each author and quote in it's own associative array and then encapsulate each one of those in one indexed array. After that, you can generate a random index. See below to demonstrate:

Code:
$quotes = array();
$quotes[] = array ( 'author' => 'Doug Larson', 'quote' => 'Life expectancy would grow by leaps and bounds if green vegetables smelled as good as bacon.');
$quotes[] = array ( 'author' => 'G.K. Chesterton', 'quote' => 'The trouble with always trying to preserve the health of the body is that it is so difficult to do without destroying the health of the mind.');

$index = rand(0,count($quotes)-1);

echo $quotes[$index]['author'];
echo $quotes[$index]['quote'];

Now if I were you, I'd generate an author and quote variable in your controller and then send it to your view (to keep that logic out of the view.)


Messages In This Thread
array - by El Forum - 09-12-2009, 10:53 AM
array - by El Forum - 09-12-2009, 11:03 AM
array - by El Forum - 09-12-2009, 11:10 AM
array - by El Forum - 09-12-2009, 11:11 AM
array - by El Forum - 09-12-2009, 12:41 PM
array - by El Forum - 09-12-2009, 02:52 PM



Theme © iAndrew 2016 - Forum software by © MyBB