mercredi 27 décembre 2017

When i have two same values in array I get Fatal error: Maximum execution time of 30 seconds exceeded in C:/Apache24/htdocs/index.php on line 18

<?php
$numbers = array("2","1","4");
$numberofelements = count($numbers);
$factorial = 1;
for ($i=1; $i<=$numberofelements; $i++)
{
         $factorial *= $i;
}
$quantitycombinations = $factorial;
$numbersdrawn = array();
while(true)
{
    $exists = false;
    $numberdrawn1 = "";
    shuffle($numbers);
    $numberdrawn1 = implode("", $numbers);
    strval($numberdrawn1);
    foreach ($numbersdrawn as $value) {
            if(strval($value)==$numberdrawn1)
            {
                $exists = true;
            }
        }
    if(!$exists){
        array_push($numbersdrawn, $numberdrawn1);
        if(count($numbersdrawn)==$quantitycombinations)
        {
            foreach($numbersdrawn as $item)
            {
                echo $item."<br>";          
            }
            break;
        }
    }
}
?>

When i change this code:

$numbers = array("2","1","4");

To

$numbers = array("2","2","4");

I get error
This code prints all combinations of the given numbers (values from array).
I changed time in php.ini file, but it didn't help.
I can not find a solution.
PLEASE HELP!!!




Aucun commentaire:

Enregistrer un commentaire