I have a multidimensional array, called $alternative
, which contains words.
This array is dynamically generated, sometimes there may only be 3 words, other times there could be 300 words.
In the below code, I am outputting the words from the array to the webpage.
How could I limit the output to say, 10 words?
foreach ($alternative as $test)
{
foreach ($test as $test2)
{
$test3 = ucwords($test2); //Capitalizes first letter of each word
printf('<li><a href="related.php?query=%1$s" title="%1$s" >%1$s</a></li>', $test3);
}
}
At the moment, on certain occasions, too many words are being displayed, and I would like to limit it to ten words.
I cannot think of a way to do this. Does anybody have any suggestions?
Thanks guys.