July 7, 201115 yr im currently in the middle of designing a website for a client and basically we have a testimonials page which i will uses simple html to document them, but we also have a right side bar on each page which currently is not doing anything so i thought it would be a good idea to write a little php script which would generate a random testimonial and echo it out into a <div>. It works fine, but each div displays the same testimonial, and obviously i want them to be completely unique. Here is the code im using im callig this from a seperate file <?php $randRotate = rand(0,4); $text[0] = 'Your text 1'; $text[1] = 'Your text 2'; $text[2] = 'Your text 3'; $text[3] = 'Your text 4'; $text[4] = 'Your text 5'; ?> And then in each separate div i have <?php echo($text[$randRotate]); ?> im not brillian with php, but i understand the concept of it. thanks for any help you can give
July 7, 201115 yr Author thats worked, i am now in theory getting a different random value, but i am still getting duplicate random entries. Is there a way i can validate it to keep randomizing the selection until the returned result is totally unique? this will be awful syntax probably but something like this.... <?php if ($text = = $text [$rand_keys]); ?> thanks
July 7, 201115 yr Author hmm, ive tried array_unique() but cant seem to get it to work php hurts my brain....
Create an account or sign in to comment