<?php require_once 'define.php'; require_once 'functions.php'; $types = array_keys($headers); $abb = abbreviations(); $classes = define_classes(); $headers = define_headers(); $types = array_keys($headers); $sql = ""; foreach ($types as $type) { $sql .= "(select * from records where type = '{$type}' and accepted = 1 order by amount desc limit 10) union "; } $sql = substr($sql, 0, -6); $res = $mysqli->query($sql); while ($f = $res->fetch_assoc()) { $id = $f['id']; $type = $f['type']; $character = $f['character']; $amount = $f['amount']; $url = $f['url']; $accepted = $f['accepted']; $faction = $f['faction']; $class = $f['class']; $patch = $f['patch']; $wztype = $f['wztype']; $added = $f['added']; $comment = $f['comment']; $data[$type][$id] = array('character' => $character, 'amount' => $amount, 'faction' => $faction, 'class' => $class, 'url' => $url, 'wztype' => $wztype, 'patch' => $patch); } foreach ($data as $type => $array) {
function gen_variation_diff_arg_values_test($fn_name, $arg_det, $which_arg, $code_block) { $names = array_keys($arg_det); $types = array_values($arg_det); $blank_line = ""; // decrement the $which_arg so that its matches with the index of $types $which_arg--; //generate code to define error handler $code_block = add_error_handler($code_block); // generate code to initialise arguments that won't be substituted array_push($code_block, "// Initialise function arguments not being substituted (if any)"); for ($i = 0; $i < count($types); $i++) { if ($i != $which_arg) { // do not generate initialization code for the argument which is being tested $i_stmt = get_variable_init_statement($types[$i], $names[$i]); array_push($code_block, $i_stmt); } } array_push($code_block, $blank_line); // generate code to unset a variable array_push($code_block, "//get an unset variable"); array_push($code_block, "\$unset_var = 10;"); array_push($code_block, "unset (\$unset_var);"); array_push($code_block, $blank_line); //define some classes $code_block = define_classes($code_block); //add heredoc string array_push($code_block, "// heredoc string"); array_push($code_block, "\$heredoc = <<<EOT"); array_push($code_block, "hello world"); array_push($code_block, "EOT;"); array_push($code_block, $blank_line); //add arrays array_push($code_block, "// add arrays"); array_push($code_block, "\$index_array = array (1, 2, 3);"); array_push($code_block, "\$assoc_array = array ('one' => 1, 'two' => 2);"); array_push($code_block, $blank_line); //generate code for an array of values to iterate over array_push($code_block, "//array of values to iterate over"); $code_block = gen_array_with_diff_values($types[$which_arg], 'inputs', $code_block); //generate code for loop to iterate over array values array_push($code_block, $blank_line); array_push($code_block, "// loop through each element of the array for {$names[$which_arg]}"); array_push($code_block, $blank_line); array_push($code_block, "foreach(\$inputs as \$key =>\$value) {"); array_push($code_block, " echo \"\\n--\$key--\\n\";"); // prepare the function call // use all arguments including the optional ones to construct a single function call $var_name = array(); foreach ($names as $nm) { array_push($var_name, "\$" . $nm); } $var_name[$which_arg] = "\$value"; $all_args = implode(", ", $var_name); array_push($code_block, " var_dump( {$fn_name}({$all_args}) );"); array_push($code_block, "};"); return $code_block; }