As mentioned earlier, my php knowledge is slim to none … are you saying I cannot use this code if I have 6 blurbs? I tried the code with 4 blurbs first as a test and still got errors.
Also, initially I tried SamA’s code but wasn’t able to make it work at all (my error, I know, not SamA’s) so I tried this code.
Okay, in googling php array random content, I found a script that looks quite similar to the one I am using, and the -1 is between the two ending parentheses on line 15 … which I honestly never would have figured out. I assumed we were talking about numbers actually written in the code (of which, there was only 0).
So I have changed my code to read:
include $blurbs[rand(-1, count($blurbs)-1)];
That appears to be working. Any other suggestions or beginning php tutorials gratefully appreciated.
Making educated guesses can work (or appear to work) sometimes, but don’t hesitate to check the documentation. IMHO PHP has very good documentation. eg.
int rand ( int $min , int $max )
If called without the optional min, max arguments rand() returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 5 and 15 (inclusive), for example, use rand(5, 15).
The array has six members (PHP calls them array elements).
They have index values ranging from 0 to 5
You could mess with this, but there is no need to complicate something that will work fine as it is.
Because count will return the integer 6 but you need max to be 5, your change to count($blurbs) - 1 is correct.
However, a min of -1 is not correct because the lowest array index is 0 not -1
Re documentation – the problem for me is that it assumes a degree of knowledge that I don’t have. So I will have to make time to google “php for idiots (or complete beginners)” and read/watch some tutorials. My only webpage skills are with html and css … and for anything else I have just enough skill to google and experiment. As you noted, that only gets you so far.