Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

View Poll Results: help me know what you think please if you comment
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. Voters: 0. You may not vote on this poll

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2012, 07:19 AM   PM User | #1
parele
New to the CF scene

 
Join Date: Mar 2012
Location: australia
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
parele is an unknown quantity at this point
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 07:33 AM..
parele is offline   Reply With Quote
Reply

Bookmarks

Tags
functions, php, restart function, restart script

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:33 AM.


Advertisement
Log in to turn off these ads.