Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.

View Poll Results: help me know what you think please if you comment

Voters
0. You may not vote on this poll
  • was this post explained well

    0 0%
  • would this post be helpful to others

    0 0%
  • is this method a bad concept(explain another one then)

    0 0%
Multiple Choice Poll.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Location
    australia
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php restart function inside function

    hi all, im really confused how to do the following task, basically im cheking for a value example:

    function counter1
    if($counter == 1){
    than start function counter2();
    }

    function counter2(){
    start function counter1();
    }

    //The above is the princible. the below code is an example of the code im working on where i have indicated where to call the function i just dont know how to.

    <?php
    $checker = 0;
    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 stop, here i should restart ";
    Here is where i want to call a function bob()


    }
    }
    $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)));

    function bob(){
    while($checker>10){
    echo "checker is at 10";
    here i want to call the function "shuffleArray($myArray) "


    }

    }

    ?>
    the output will shuffle this array (1,5,5,3,7,7,7,7)except the numbers will not be next to each other for example 1,7,5,7,3,7,5,7 if this results fails than it will process again until the result is acceptable, there are many outcomes that could output" all outputs are exceptable if the numberes are not together but sometimes the random shuffle may create the following 1,5,3,7,5,7 and allthat is left is 7's wich is not acceptable so when this happens i want to rerun the script.
    Last edited by parele; 03-07-2012 at 08:33 AM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •