How can I call functions in different orders in PHP? -
i making way organize user groups , need way check them. example have method check gender, return true if there no gender imbalance , false if there is. have similar methods check age distribution , check genders. each of these methods have method makes optimized array of groups.
i.e. have method optimizes groups based on gender. call 1 of these methods if respective check returns false. problem running when optimize groups based on specific criterion i.e. gender, there chance new optimized groups have messed check criterion.
for example, if check age, gender , skill level (my third check) , find there imbalance in age, proceed optimize groups respect age, potentially mess gender or skill level distributions. solution problem if find way call variations of check methods , break if check method returned true (all checks return true, groups have balances of age, gender , skill level).
ex: let a, b , c check methods , optimize_a, optimize_b, optimize_c make optimized group methods. need way loop through check methods 3! times (because there 3 check methods , need run abc, acb, bac, bca, cab, cba). or while loop , break if method check () returns true (all checks return true, have distributions) , break once have run combinations of check methods.
could me problem? please bear in mind novice programmer , have never done before. thanks
edit:
how javascript code snippet in php?
var arr = [check1, check2, check3], rand = math.floor(math.random() * arr.length), func = arr[rand]; func(); here attempt:
<?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->.$func.($tmp); // $tmp array of groups ?>
you almost had it, remove dots @ end.
$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->$func($tmp); // $tmp array of groups
Comments
Post a Comment