mardi 27 octobre 2015

Change variable value each time its called

I've used a variable that is set by choosing a word from an array (using time as the "random" index) throughout a site. Everything works great.

However - on some pages that variable is displayed multiple times, and each time it displays the same word.

Because I've hardcoded the variable (and randomly generated it on page load), it will be a massive headache to go through and change the variable to a function that instead returns the word. (This was not done in the first place for a reason - that didn't take the duplication into account.)

Here's the question: Is there a way to make a variable change its value each time its called?

I was thinking something along the lines of

<?php
$var = function returnNewWord(){
      /* generate random word here */
      return $ranWord;
}
?>

That does not work - but it may give you an idea of what I mean.

Anyone know how this may be possible? Thank you for your help.




Aucun commentaire:

Enregistrer un commentaire