Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8129009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:07:41+00:00 2026-06-06T08:07:41+00:00

I found this random page script which is in PHP file. I’m a bit

  • 0

I found this random page script which is in PHP file. I’m a bit frustrated that it’s hard to refresh the page when I click on refresh (reload) on the browser. Each random page has an article and some have two images but mostly one image. There is only 3 articles.

The issue is that it takes 2 or 3 clicks in order to refresh the page. There’s No button, it only refreshed the page when you click ‘reload’ the page on the browser (all browser) or visit to the site. In order for it to work it does always take at least 2 or 3 clicks to refreshed.

Here is the code:

<?php
$pagesArray = array("article1.php", "article2.php", "article3.php");
$randNum = rand(0, count($pagesArray)-1);
echo $pagesArray[$randNum];
?> 

I also try modify the script to used “shuffle”

<?php
$pagesArray = array("article1.php", "article2.php", "article3.php");
shuffle($pagesArray);
echo $pagesArray[0];
?> 

and also to used “array_rand”

<?php
$pagesArray = array("article1.php", "article2.php", "article3.php");
array_rand($pagesArray);
echo $pagesArray[0];
?> 

Is there a way to make the code better? I just want the code to refresh the different pages rather clicking 2 or 3 times for it to work. I appreciate any suggestion how to make it works correctly or any example would be appreciate for me to see the full picture!

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T08:07:43+00:00Added an answer on June 6, 2026 at 8:07 am

    I’m not familiar with PHP, but if you’re asking which method of selecting a random element in your array is fastest, I would guess that is option 1. Generating a random integer takes constant time, and returning an element of an array by the array index should take constant time as well. I don’t know how shuffle is implemented, but I’m pretty sure getting a random number would take less time than shuffling an array of elements. Whatever the case, there shouldn’t be a noticeable difference to the user if you only have a few elements in your array.

    As for why it takes 2 or 3 refreshes for it to “work”, I’m guessing that is probably because you’re just returning the same page multiple times. If you can get what page the user is currently on (or has visited), you can just remove the item from the array before picking one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this script for a Find In Page / Highlight / ScrollTo feature
I found this code using Google. private int RandomNumber(int min, int max) { Random
I'm trying to produce random integers (uniformly distributed). I found this snippet on an
found this little code snippet that seems to do what i want, but im
I have a python script which should parse a file and produce some output
I have a php script that returns an echo of 'Hello' when accessed half
This blog post (slightly annoying page there) (and that's not my blog by the
I found this bit of code on stackoverflow at Best practices on displaying search
Found this while reading the Neo4j manual, specifically here , I found the sentence:
Found This: tyty stack, Social Icons not working with Infinite Scrolling on Wordpress I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.