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 7624573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:59:55+00:00 2026-05-31T04:59:55+00:00

`I have a function called lets say calculate; what i want to do is

  • 0

`I have a function called lets say calculate; what i want to do is run some loops with in the function calculating an outcome. at times this function does fail as it will get stuck in a loop, so iv got it covered to exit the loop but my problem is i want to restart this function and hope it come out with an outcome if not i will try again… on average the request does not have an outcome around 1 in 20, i need to restart the function from a clean slate.

i have tried to unset all the vars before i rerun the process with out success.please note this function will fail at times from the information handed to the process, un avoidable so
when this accurs i just want to rerun the function automatically to generate an outcome.

http://www.gamezslave.com/test/DynamicSlots.swf this is my test prototype give you an idea
sometimes you refresh it will error because of this factor.

<?php
$checker = 0; // if i cant get a result i could use this will tick up until condition
function shuffleArray($myArray) {
    $value_count = array_count_values($myArray);
    $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));
    echo "stuck";
            $checker++;
    if($checker>10){
        echo " Too many checks so die, and restart process ";
        return false;
        bob; // this is the check function to goto and restart
    }
        }
        $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_slice($shuffle, $i + 1, 0, $last_value);
    } else {
        $shuffle[] = $last_value;
    }
    return $shuffle;
}

print_r(shuffleArray(array(1,5,5,3,7,7,7,7))); // just a example
function bob(){
if($checker>10){
    $checker = 0;
    shuffleArray();
    echo "bob";
        reset($myArray); // thought this may clean/reset the array i couldnt use
    }
}

The idea this shuffle returns that no two symbols elemts of the same will be next to each other but sometimes at the end of the array as its shuffling randomly im left with bad odds (apple, orange, orange, orange) so what i need to do is resart this process again from start take in mind there is about 10 different item in the array and duplicates of each for example 10 apples ,10 oranges 4 bannanas 3 grapes sometimes the shuffle manages to generate an outcome where im stuck with too many of the same item at the end of the array wich then i need to rerun the script(and this bit is the problem) i dont know how.

  • 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-31T04:59:56+00:00Added an answer on May 31, 2026 at 4:59 am

    I would set defaults to all variables inside of your function, and pass anything active as a parameter. Then use a set of return codes to indicate success or failure, or validate the outcome in some way and re-run.

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

Sidebar

Related Questions

Lets say I have code: $('#target').click(function() { alert('Handler for .click() called.'); }); I want
Lets say you have some functions in some classes are called together like this
Lets say I have a class like this in Java: public class Function {
Lets say that in this case i have 4 divs called .CountThese and i
I have this function which is called about 1000 times from main(). When i
Lets say I have a function called do3() In order for that function to
lets say i have a function called simpleFunction(); that i call a bunch of
I have this function called ProperCase that takes a string, then converts the first
Now I'm sure this is super easy, I have a function called remove_deposit which
Suppose I have a free function called InitFoo . I'd like to protect this

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.