Hello, I am new to PHP. I have a code which randomly selects twelve blocks of code from an array of a couple hundred without repeating. Each block codes for an image, its name, and the rating for it. It looks something like this:
<?php
// Just to shorten the title of the image
function getTitle($name) {
$pos=16;
$post = substr($name, 0, $pos);
if (strlen($name) > 16) {return $post."...";}
else {return $post;}
}
$title = getTitle;
// This gives the rating for the image
// Function declared in a different php file
$pullrating=pullRating;
$images=array(
"{$title(image1name)} img src here 1.jpg {$pullrating1}\n", // For Example
"{$title(image2name)} img src here 2.jpg {$pullrating2}\n", // For Example
"{$title(image3name)} img src here 3.jpg {$pullrating3}\n" // For Example
);
srand(time());
shuffle($images);
for ($i=0;$i<12;++$i) // display my twelve images
echo "$images[$i]";
?>
This code works really well for me. It randomly selects twelve images with their titles and their ratings by randomly selecting their respective coding.
My problem is this: when I randomly select four, my page loads pretty quickly. However when I load twelve, I feel like my page takes a while to load (in both Firefox and IE). Is there a more efficient way to write my code? I know I really shouldn't be attempting to execute functions through a variable. If you think you may have a fix, please keep in mind that the blocks of code cannot repeat. Thanks for reading everything-