Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I call functions in different orders in PHP?
    primarykey
    data
    text
    <p>I am making a way to organize user into groups and need a way to check them. For example I have a method to check gender, which return true if there is no gender imbalance and false if there is. I also have similar methods to check age distribution and to check genders. For each of these methods I have a method which makes an optimized array of groups. </p> <p>I.e. i have a method which optimizes groups based on gender. I would only call one of these methods if the respective check returns false. The problem I am running into is that when I optimize the groups based on a specific criterion i.e. gender, there is a chance that the new optimized groups have messed up another check criterion. </p> <p>For example, if I check age, gender and skill level (my third check) and I find that there is an imbalance in age, proceed to optimize the groups with respect to age, then I could potentially mess up gender or skill level distributions. My solution to this problem was that If I could find a way call all variations of the check methods and break if a check all method returned true (all checks return true, all groups have good balances of age, gender and skill level). </p> <p>Ex: Let A, B and C be check methods and optimize_A, optimize_B, optimize_C be the make optimized group methods. I need some way loop through the check methods 3! times (because there are 3 check methods and I need to run ABC, ACB, BAC, BCA, CAB, CBA). OR I could do a while loop and break if the method check all () returns true (all checks return true, all have good distributions) and break once I have run the all the combinations of the check methods. </p> <p>Could anyone help me with this problem? Please bear in mind I am a novice programmer and have never done anything like this before. Thanks</p> <p><b>Edit</b>: </p> <p>How could I do something like this JavaScript code snippet in php?</p> <pre><code>var arr = [check1, check2, check3], rand = Math.floor(Math.random() * arr.length), func = arr[rand]; func(); </code></pre> <p>Here is my attempt:</p> <pre><code>&lt;?php $checks_to_run = array('check_gender','check_age','check_skill_level'); $rand = floor(rand(0, count($checks_to_run) - 1)); $func = $checks_to_run[$rand]; echo $this-&gt;.$func.($tmp); // $tmp is an array of groups ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload