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

  • SEARCH
  • Home
  • 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 7629033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:43:57+00:00 2026-05-31T05:43:57+00:00

this is my first php script and problem, I’ve searched hours with no conclusion

  • 0

this is my first php script and problem, I’ve searched hours with no conclusion other than looping a function" too many laterations". but it doesn’t solve my problem I’ve never studied programming or what ever so I’m hoping that there is an educated person to fill me in on this:

I have an array that contains 120 elements; consists of duplicates eg:

myArray = [0]= item_1, [1] = item _1, [2] = item_2, [3] = item_3 ect..

Briefly I’m trying to make a flash php pokermachine but I need these items in the array to be shuffled BUT I do not want the duplicates to be next to each other after the shuffle but I need the duplicates to be still in the array

I can’t do a loop function to check this because it will change the shuffle too many times which will effect the odds of the game: below is what I currently have:

/ * Removed the link here that is no longer available */

you may notice at times it will double up with 2 items in the same reel
Basically I created the virtual reel dynamically with php.ini file
these values are repeatedly pushed into an array($virtualreel) so the value may appear 10 times in the reel and another value will appear 5 times variating the odds. Then after I take a random slice() from the $virtualreel to display 3 vars from this reel and repeat the loop 4 more times for the other reels, also I only can shuffle once as I want the slice() to be from the same reels array order

I only shuffle every new spin not running loop functions to shuffle if I double up on a slice(array,3 items).

hope I’ve explained what I’m after well enough to give you guys an idea.

  • 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-05-31T05:43:58+00:00Added an answer on May 31, 2026 at 5:43 am

    You can use this function:

    <?php
    
    function shuffleArray($myArray) {
      $value_count = array_count_values($myArray);
      foreach($value_count as $key=>$value) {
          if ($value > count($myArray)/2) {
               return false;
          }
      }
      $last_value = $myArray[count($myArray) - 1];
      unset($myArray[count($myArray) - 1]);
      $shuffle = array();
      $last = false;
      while (count($myArray) > 0) {
        $keys = array_keys($myArray);
        $i = round(rand(0, count($keys) - 1));
        while ($last === $myArray[$keys[$i]]) {
            $i = round(rand(0, count($keys) - 1));
        }
        $shuffle[] = $myArray[$keys[$i]];
        $last = $myArray[$keys[$i]];
        unset($myArray[$keys[$i]]);
      }
    
      if ($last_value === $last) {
        $i = 0;
        foreach($shuffle as $key=>$value) {
            if ($value !== $last_value) {
                $i = $key;
                break;
            }
        }
        array_splice($shuffle, $i + 1, 0, $last_value);
      } else {
        $shuffle[] = $last_value;
      }
    
      return $shuffle;
    }
    
    print_r(shuffleArray(array(1,5,5,3,7,7)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this on a website, css_loader.php <?php // First of all send css
This is my first question :). Im writing a little twitter app in PHP
Hello everyone I am a newbie to php and this is my first ever
This is user.php: include(databse.php);//retrieving successfully first name and lastname from databse file into user.php
when I run this code for the first time <?php session_start(); echo SID; ?>
I downloaded a program implemented in Java (in this case, http://julian.togelius.com/mariocompetition2009/index.php ). I first
I have a really confusing problem. I have a PHP script that polls another
I'm using this code to submit a form to a php script: var valid
So I have this in my PHP script on my test site: $file=clip.mp4; $fake=clip_testing.mp4;
I am new to PHP so please forgive if this question or problem seem

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.