function foo($action, ...$num) { if (is_string(func_get_arg(0))) { calc($num, $action); } else { echo 'First argument of fucntion must have type STRING '; } }
function getclub($who, &$c1, &$c2, &$c3) { global $db, $tablepre, $starttime, $validtime; $result = $db->query("SELECT gid FROM {$tablepre}winners ORDER BY gid desc LIMIT 1"); $t = $db->fetch_array($result); $curgid = $t['gid'] + 1; $result = $db->query("SELECT uid FROM {$tablepre}users WHERE username='******'"); $t = $db->fetch_array($result); $curuid = $t['uid'] + 2; $result = $db->query("SELECT pid FROM {$tablepre}players WHERE name='{$who}' AND type=0"); $t = $db->fetch_array($result); $curpid = $result['pid'] + 3; $c1 = calc(12347, 10007, $curgid, $curuid, $curpid, $starttime, $validtime); $c1 %= 6; if ($c1 == 0) { $c1 = 9; } //超能称号为9号 $delt = 0; while ($delt <= 30) { $c2 = calc(10009, 7789 + $delt, $curgid, $curuid, $curpid, $starttime, $validtime); $c2 %= 5; $c2++; //第二个称号不允许超能 if ($c1 != $c2) { break; } $delt++; } if ($delt > 30) { if ($c1 == 1) { $c2 = 2; } else { $c2 = 1; } } $c3 = calc(11131, 6397, $curgid, $curuid, $curpid, $starttime, $validtime); $clubid = array(6, 7, 8, 99, 10, 11, 13, 14, 16, 18, 19, 7, 99, 13, 14, 18, 6, 19, 13, 14, 18); $c3 %= 21; $c3 = $clubid[$c3]; if ($c1 == $c3 || $c2 == $c3) { $c3 = 99; } if ($c1 > $c2) { swap($c1, $c2); } if ($c1 > $c3) { swap($c1, $c3); } if ($c2 > $c3) { swap($c2, $c3); } }
function start() { global $stopTime, $iterations, $N, $T, $res; $stopTime = microtime(true) + $T; // NOW + T seconds while (microtime(true) < $stopTime) { reinit(); calc($N); $iterations++; } $iterations--; // last iteration started before time was up but finished after time was up // required '>' mark for automatic benchmark print "> {$iterations} iterations\n"; print "Resulting F({$N}) = {$res[$N - 1 & 3]}\n"; }
function start() { global $stopTime, $iterations, $T, $res, $n, $m; $stopTime = microtime(true) + $T; // NOW + T seconds while (microtime(true) < $stopTime) { reinit(); calc(); $iterations++; } $iterations--; // last iteration started before time was up but finished after time was up // required '>' mark for automatic benchmark print "> {$iterations} iterations\n"; print "Resulting LCS(X, Y) = {$res[$n][$m]}\n"; outputLCS(); }
public function updateModels($k) { // $k is match id // get all predictions with that match id // calculate points and update each row $arr = ['fields' => ['id', 'score', 'gotw'], 'conditions' => ['id' => $k], 'contain' => ['Prediction' => ['fields' => ['id', 'pred', 'joker']], 'Bet' => ['fields' => ['id', 'prediction']]]]; $preds = $this->find('all', $arr); $preds = $preds[0]; // simplify the array $score = $preds['Match']['score']; $gotw = $preds['Match']['gotw']; // get the result to compare to each bet made @(list($sa, $sb) = explode('-', $score)); if ($sa > $sb) { $result = '1'; } elseif ($sa < $sb) { $result = '2'; } elseif ($sa == $sb) { $result = 'X'; } // loop through each prediction foreach ($preds['Prediction'] as $p) { $pts = calc($p['pred'], $score, $p['joker'], $gotw); $tosave = ['Prediction' => ['id' => $p['id'], 'points' => $pts]]; if ($this->Prediction->save($tosave)) { //$this->log(__('updated score to %s for prediction %s', $pts, $p['id']), 'admin'); } else { $this->log(__('Couldn\'t update score for prediction %s ', $p['id']), 'admin'); } } // get all bets with that match id // calculate right/wrong and update each row foreach ($preds['Bet'] as $b) { $tosave = ['Bet' => ['id' => $b['id'], 'outcome' => (int) ($result == $b['prediction'])]]; if ($this->Bet->save($tosave)) { // do something on save } else { $this->log(__('Couldn\'t update outcome for bet %s ', $p['id']), 'admin'); } } }
function deal() { if (empty($_REQUEST['answer'])) { fail("answer缺失"); } if (empty($_REQUEST['id'])) { fail("id缺失"); } $conn = @mysql_connect("localhost", "root", "mobilenewspaper") or die("数据库链接错误"); $right = array(8, 4, 4, 1, 1, 2, 1, 1, 2, 4, 8, 8, 4, 2, 1, 4, 4, 1, 1, 8, 4, 1, 8, 7, 15, 7, 7, 5, 7, 3); list($score, $type) = calc($_REQUEST['answer'], $right); mysql_select_db("qa", $conn); $result = mysql_query("select id from questionnaire order by id desc limit 1", $conn); $row = mysql_fetch_assoc($result); $id = $row['id'] + 1; $SQL = "INSERT INTO questionnaire (titleid, score, answer) VALUES ( " . $_REQUEST['id'] . "," . str($score) . ",\"" . $_REQUEST['answer'] . "\")"; $score = $SQL; // $SQL="SELECT * FROM questionnaire order by id desc"; $query = mysql_query($SQL, $conn); resubmit($type, $score, $id); // echo "ok"; }
<tr> <th>Image</th> <th>Size</th> <th>Type</th> <th>Last Modified</th> <th>Action</th> </tr> </thead> <tbody> <? foreach ($retval as $file) { ?> <tr> <td><? echo "<a href=\"{$root}/{$dir}/{$file["name"]}\" title=\"{$file["name"]}\"><img src=\"phpThumb.php?src=pics/{$file["name"]}&w=96\" /></a>"; ?></td> <td style="text-align: right"><? echo calc($file["size"]); ?></td> <td><? echo "{$file["type"]}"; ?></td> <td><? echo date('r', $file["lastmod"]); ?></td> <td><a class="delete_link" href="delete.php" data-filename="<? echo $file["name"]; ?>">Delete</a></td> </tr> <? } ?> </tbody> </table> </div> <script> <!-- $(function() { $('a.delete_link').click(function() { try
$table[] = array("Parameter" => $name, "Value" => sprintf("%d", $load * 10)); $smarty->assign("footnote", "<p>* below 10 is good, above 20 is worse, above 40 is bad.</p>"); $table[] = array("Parameter" => '', "Value" => ''); } fclose($f); } } } $sql = "SELECT count(*) FROM event WHERE status='pending'"; calc("Pending Hamster Tasks", $sql); $sql = "SELECT COUNT(*) FROM mapcache WHERE age > 0 AND type_or_user >= -1"; calc("Map tiles to redraw", $sql); $sql = "SELECT COUNT(*) FROM kmlcache WHERE rendered = 0"; calc("Superlayers tiles to update", $sql); $sql = "SELECT COUNT(DISTINCT url) FROM gridimage_link WHERE next_check < NOW()"; calc("Links waiting to be checked", $sql); $smarty->assign_by_ref('table', $table); $smarty->assign("h2title", $title); $smarty->assign("total", count($table)); $smarty->assign("nosort", 1); } $smarty->display($template, $cacheid); function calc($name, $sql, $cache = 0) { global $db, $table; if ($cache) { $val = $db->cacheGetOne($cache, $sql); } else { $val = $db->getOne($sql); } $table[] = array("Parameter" => $name, "Value" => $val);
$res_a[26] = 14100; $res_a[27] = 15600; $res_a[28] = 17200; $res_a[29] = 19000; $res_a[30] = 20900; //test info soon database $lvl_a = 5; $time_begin = 1000; $time_end = 1060; $start_res_a = 1000; //begin resources a //end test info function calc($lvl, $time_begin, $time_end, $start_res, $res_lvl) { $calc = ($time_end - $time_begin) * ($res_lvl / 3600); $total = $start_res + $calc; $rtotal = round($total, 2); print "---------------------------------<br>"; print "Level {$lvl} <br>"; print "---------------------------------<br>"; print "Begin resources {$start_res} <br>"; print "Adding resources {$calc} <br>"; print "End resources {$rtotal} <br>"; print "---------------------------------<br><br>"; } $i = 1; while ($i <= 30) { calc($i, $time_begin, $time_end, $start_res_a, $res_a[$i]); $i++; } $i = 1;
* User: essamamdani * Date: 26/04/16 * Time: 4:29 PM */ $total = 0; function calc($val1, $val2) { global $total; $total = $val1 + $val2; } function getTotal() { global $total; echo $total; } calc(2, 5); $total = 15; getTotal(); //Object Oriented Programming class Math { //Encapsulation (private, protected, public) private $total = 0; // Inheritance (Weerasat) function calc($val, $val2) { //SET $this->total = $val + $val2; } function getTotal() {
public function updateLeague($week) { // called on updating results // get all scores for players // write results to Standings table $sql = 'SELECT U.id, U.username, P.pred, P.joker, M.id, M.score, M.gotw FROM users U JOIN predictions P ON U.id = P.user_id JOIN matches M ON P.match_id = M.id WHERE (U.games & 1) != 0 AND (M.game & 1) != 0 AND M.week_id = ?'; $db = $this->getDataSource(); $data = $db->fetchAll($sql, [$week]); $table = []; $goals = []; foreach ($data as $w) { $uid = $w['U']['id']; $mid = $w['M']['id']; @($table[$uid]['goals'] += array_sum(explode('-', $w['P']['pred']))); if (!is_null($w['M']['score'])) { $score = calc($w['P']['pred'], $w['M']['score'], $w['P']['joker'], $w['M']['gotw']); @($table[$uid]['score'] += $score); if (empty($goals[$mid])) { $goals[$mid] = array_sum(explode('-', $w['M']['score'])); } } else { @($table[$uid]['score'] += 0); } } $goalsum = array_sum($goals); if (!empty($table)) { foreach ($table as $k => $n) { $goal_diff[$k] = abs($goalsum - $n['goals']); } } $closest = getmin($goal_diff); foreach ($table as $k => &$n) { if (in_array($k, $closest)) { $n['score'] += 3; } } ksort($table); uasort($table, function ($x, $y) { return $x['score'] > $y['score'] ? -1 : 1; }); $this->Standing->deleteAll(['week_id' => $week]); $row = 0; // which row are we on $rank = 0; // what is the rank of the player $absrank = 0; // what is abs score $prevrank = 0; // rank of row n-1 foreach ($table as $k => &$n) { $absrank = $n['score']; if ($absrank == $prevrank) { $row++; } else { $rank = ++$row; } $prevrank = $absrank; $tosave = ['Standing' => ['week_id' => $week, 'user_id' => $k, 'points' => $n['score'], 'position' => $rank]]; $this->Standing->create(); if ($this->Standing->save($tosave)) { // TODO something } else { $this->log('Couldn\'t update standings', 'admin'); } } }
if ($i == 1) { echo "-"; } } else { echo rand(0, 9); } } ?> <hr> <h3>Opdracht 4</h3> <?php function calc($aantalAppels, $aantalDrop) { $appels = $aantalAppels * 0.58; $drop = $aantalDrop * 1.29; setlocale(LC_ALL, 'it_IT@euro', 'it_IT', 'it'); $totaalInc = $appels + $drop; $btw = $totaalInc * 0.21; echo round($btw, 2) . "<br />"; echo $exBtw = $totaalInc - $btw . "<br />"; echo round($totaalInc, 2) . "<br />"; } calc(10, 5); echo ""; ?> </div> </body> </html>
function doLettre($id_bibli, $id_cde) { global $msg, $acquisition_gestion_tva; //On récupère les infos de la commande $cde = new actes($id_cde); $lignes = actes::getLignes($id_cde); $bib = new entites($cde->num_entite); $coord_liv = new coordonnees($cde->num_contact_livr); $coord_fac = new coordonnees($cde->num_contact_fact); $fou = new entites($cde->num_fournisseur); $coord_fou = entites::get_coordonnees($cde->num_fournisseur, '1'); $coord_fou = pmb_mysql_fetch_object($coord_fou); $this->PDF->AddPage(); $this->PDF->npage = 1; //Affichage logo if ($bib->logo != '') { $this->PDF->Image($bib->logo, $this->x_logo, $this->y_logo, $this->l_logo, $this->h_logo); } //Affichage raison sociale $raison = $bib->raison_sociale; $this->PDF->setFontSize($this->fs_raison); $this->PDF->SetXY($this->x_raison, $this->y_raison); $this->PDF->MultiCell($this->l_raison, $this->h_raison, $raison, 0, 'L', 0); //Affichage date $ville $ville_end = stripos($coord_fac->ville, "cedex"); if ($ville_end !== false) { $ville = trim(substr($coord_fac->ville, 0, $ville_end)); } else { $ville = $coord_fac->ville; } if ($cde->date_valid != '0000-00-00') { $date = $ville . $this->sep_ville_date . format_date($cde->date_valid); } else { $date = $ville . $this->sep_ville_date . format_date($cde->date_acte); } $this->PDF->setFontSize($this->fs_date); $this->PDF->SetXY($this->x_date, $this->y_date); $this->PDF->Cell($this->l_date, $this->h_date, $date, 0, 0, 'L', 0); //Affichage coordonnees fournisseur //si pas de raison sociale définie, on reprend le libellé //si il y a une raison sociale, pas besoin if ($fou->raison_sociale != '') { $adr_fou = $fou->raison_sociale . "\n"; } else { $adr_fou = $coord_fou->libelle . "\n"; } if ($coord_fou->adr1 != '') { $adr_fou .= $coord_fou->adr1 . "\n"; } if ($coord_fou->adr2 != '') { $adr_fou .= $coord_fou->adr2 . "\n"; } if ($coord_fou->cp != '') { $adr_fou .= $coord_fou->cp . " "; } if ($coord_fou->ville != '') { $adr_fou .= $coord_fou->ville . "\n\n"; } if ($coord_fou->contact != '') { $adr_fou .= $coord_fou->contact; } $this->PDF->setFontSize($this->fs_adr_fou); $this->PDF->SetXY($this->x_adr_fou, $this->y_adr_fou); $this->PDF->MultiCell($this->l_adr_fou, $this->h_adr_fou, $adr_fou, 0, 'L', 0); //Affichage adresse facturation $adr_fac = $this->text_adr_fac . "\n"; if ($coord_fac->libelle != '') { $adr_fac .= $coord_fac->libelle . "\n"; } if ($coord_fac->adr1 != '') { $adr_fac .= $coord_fac->adr1 . "\n"; } if ($coord_fac->adr2 != '') { $adr_fac .= $coord_fac->adr2 . "\n"; } if ($coord_fac->cp != '') { $adr_fac .= $coord_fac->cp . " "; } if ($coord_fac->ville != '') { $adr_fac .= $coord_fac->ville . "\n"; } if ($coord_fac->tel1 != '') { $adr_fac .= $this->text_adr_fac_tel . " " . $coord_fac->tel1 . "\n"; } if ($coord_fac->tel2 != '') { $adr_fac .= $this->text_adr_fac_tel2 . " " . $coord_fac->tel2 . "\n"; } if ($coord_fac->fax != '') { $adr_fac .= $this->text_adr_fac_fax . " " . $coord_fac->fax . "\n"; } if ($coord_fac->email != '') { $adr_fac .= $this->text_adr_fac_email . " " . $coord_fac->email . "\n"; } if ($bib->tva) { $adr_fac .= $msg["acquisition_tva"] . ": " . $bib->tva . "\n"; } $this->PDF->setFontSize($this->fs_adr_fac); $this->PDF->SetXY($this->x_adr_fac, $this->y_adr_fac); $this->PDF->MultiCell($this->l_adr_fac, $this->h_adr_fac, $adr_fac, 1, 'L', 0); //Affichage adresse livraison $adr_liv = ''; if ($coord_liv->libelle != '') { $adr_liv .= $coord_liv->libelle . "\n"; } if ($coord_liv->adr1 != '') { $adr_liv .= $coord_liv->adr1 . "\n"; } if ($coord_liv->adr2 != '') { $adr_liv .= $coord_liv->adr2 . "\n"; } if ($coord_liv->cp != '') { $adr_liv .= $coord_liv->cp . " "; } if ($coord_liv->ville != '') { $adr_liv .= $coord_liv->ville . "\n"; } if ($coord_liv->tel1 != '') { $adr_liv .= $this->text_adr_liv_tel . " " . $coord_liv->tel1 . "\n"; } if ($coord_liv->tel2 != '') { $adr_liv .= $this->text_adr_liv_tel2 . " " . $coord_liv->tel2 . "\n"; } if ($coord_liv->email != '') { $adr_liv .= $this->text_adr_liv_email . " " . $coord_liv->email . "\n"; } if ($adr_liv != '') { $adr_liv = $this->text_adr_liv . "\n" . $adr_liv; $this->PDF->setFontSize($this->fs_adr_liv); $this->PDF->SetXY($this->x_adr_liv, $this->y_adr_liv); $this->PDF->MultiCell($this->l_adr_liv, $this->h_adr_liv, $adr_liv, 1, 'L', 0); } //Affichage tiret pliage $this->PDF->Line(0, 105, 3, 105); $this->y = $this->PDF->GetY(); $this->PDF->Ln(); $this->PDF->Ln(); //Affichage numero client $numero_cli = $this->text_num_cli . " " . $fou->num_cp_client; $this->PDF->SetFontSize($this->fs_num); $this->PDF->SetXY($this->x_num, $this->y_num); $this->PDF->Cell($this->l_num_cli, $this->h_num, $numero_cli, 0, 0, 'L', 0); $this->PDF->Ln(); //Affichage numero commande $numero = $this->text_num . $cde->numero; $this->PDF->SetFontSize($this->fs_num); $this->PDF->Cell($this->l_num, $this->h_num, $numero, 0, 0, 'L', 0); $this->PDF->Ln(); //Affichage reference if ($cde->reference != '') { $ref = $this->text_ref . $cde->reference; $this->PDF->SetFontSize($this->fs); $this->PDF->Cell($this->w, $this->h_tab, $ref, 0, 0, 'L', 0); $this->PDF->Ln(); $this->PDF->Ln(); } //Affichage texte before + commentaires if ($cde->commentaires_i != '') { if ($this->text_before != '') { $this->text_before .= "\n\n"; } $this->text_before .= $cde->commentaires_i; } if ($this->text_before != '') { $this->PDF->SetFontSize($this->fs); $this->PDF->MultiCell($this->w, $this->h_tab, $this->text_before, 0, 'J', 0); } //Affichage lignes commandes $this->PDF->SetAutoPageBreak(false); $this->PDF->AliasNbPages(); $this->PDF->SetFontSize($this->fs_tab); $this->PDF->SetFillColor(230); $this->y = $this->PDF->GetY(); $this->PDF->SetXY($this->x_tab, $this->y); $tab_mnt = array(); $i = 0; while ($row = pmb_mysql_fetch_object($lignes)) { $typ = new types_produits($row->num_type); $col1 = $typ->libelle; if ($row->code) { $col1 .= "\n" . $row->code; } $col2 = $row->libelle; $col3 = $row->nb; $col4 = number_format(round($row->prix, 2), 2, '.', '') . " " . $cde->devise; if ($acquisition_gestion_tva) { $col4 .= "\n" . number_format(round($row->tva, 2), 2, '.', '') . " %"; } $col4 .= "\n" . number_format(round($row->remise, 2), 2, '.', '') . " %"; $col5 = ''; if ($row->date_ech != '0000-00-00') { $col5 = formatdate($row->date_ech); } if ($row->num_rubrique) { $rub = new rubriques($row->num_rubrique); if ($rub->num_cp_compta) { $col5 .= "\n\n" . $rub->num_cp_compta; } } //Est ce qu'on dépasse ? $this->h = $this->h_tab * max($this->PDF->NbLines($this->w_col1, $col1), $this->PDF->NbLines($this->w_col2, $col2), $this->PDF->NbLines($this->w_col3, $col3), $this->PDF->NbLines($this->w_col4, $col4), $this->PDF->NbLines($this->w_col5, $col5)); $this->s = $this->y + $this->h; if (!$this->p_header) { $this->s = $this->s + $this->h_header; } //Si oui, chgt page if ($this->s > $this->hauteur_page - $this->marge_bas - $this->fs_footer) { $this->PDF->AddPage(); $this->y = $this->y_tab; $this->p_header = false; } if (!$this->p_header) { $this->doEntete(); $this->y += $this->h_header; } $this->p_header = true; $this->PDF->SetXY($this->x_col1, $this->y); $this->PDF->Rect($this->x_col1, $this->y, $this->w_col1, $this->h); $this->PDF->MultiCell($this->w_col1, $this->h_tab, $col1, 0, 'L'); $this->PDF->SetXY($this->x_col2, $this->y); $this->PDF->Rect($this->x_col2, $this->y, $this->w_col2, $this->h); $this->PDF->MultiCell($this->w_col2, $this->h_tab, $col2, 0, 'L'); $this->PDF->SetXY($this->x_col3, $this->y); $this->PDF->Rect($this->x_col3, $this->y, $this->w_col3, $this->h); $this->PDF->MultiCell($this->w_col3, $this->h_tab, $col3, 0, 'R'); $this->PDF->SetXY($this->x_col4, $this->y); $this->PDF->Rect($this->x_col4, $this->y, $this->w_col4, $this->h); $this->PDF->MultiCell($this->w_col4, $this->h_tab, $col4, 0, 'R'); $this->PDF->SetXY($this->x_col5, $this->y); $this->PDF->Rect($this->x_col5, $this->y, $this->w_col5, $this->h); $this->PDF->MultiCell($this->w_col5, $this->h_tab, $col5, 0, 'R'); $this->y += $this->h; $tab_mnt[$i]['q'] = $row->nb; $tab_mnt[$i]['p'] = $row->prix; $tab_mnt[$i]['r'] = $row->remise; $tab_mnt[$i]['t'] = $row->tva; $i++; } $this->PDF->SetAutoPageBreak(true, $this->marge_bas); $this->PDF->SetX($this->marge_gauche); $this->PDF->SetY($this->y); $this->PDF->SetFontSize($this->fs); $this->PDF->Ln(); //affichage des montants ht, ttc, tva $tab_tot = calc($tab_mnt, 2); $this->y = $this->PDF->GetY(); if ($acquisition_gestion_tva) { $this->h = $this->h_tot * 3; } else { $this->h = $this->h_tot; } $this->s = $this->y + $this->h; if ($this->s > $this->hauteur_page - $this->marge_bas) { $this->PDF->AddPage(); $this->PDF->SetXY($this->x_tot, $this->marge_haut); $this->y = $this->PDF->GetY(); } if ($acquisition_gestion_tva) { $this->PDF->Cell($this->l_tot, $this->h_tot, $msg['acquisition_total_ht'], 1, 0, 'L', 0); $this->PDF->Cell($this->l_tot, $this->h_tot, number_format($tab_tot['ht'], 2, '.', '') . " " . $cde->devise, 1, 1, 'R', 0); $this->PDF->Cell($this->l_tot, $this->h_tot, $msg['acquisition_tva'], 1, 0, 'L', 0); $this->PDF->Cell($this->l_tot, $this->h_tot, number_format($tab_tot['tva'], 2, '.', '') . " " . $cde->devise, 1, 1, 'R', 0); } $this->PDF->Cell($this->l_tot, $this->h_tot, $msg['acquisition_total_ttc'], 1, 0, 'L', 0); $this->PDF->Cell($this->l_tot, $this->h_tot, number_format($tab_tot['ttc'], 2, '.', '') . " " . $cde->devise, 1, 1, 'R', 0); $this->PDF->Ln(); //Affichage conditions de paiement $text_paiement = $msg['acquisition_mode_pai']; if ($fou->num_paiement) { $pai = new paiements($fou->num_paiement); $text_paiement .= "{$pai->libelle}"; $this->PDF->MultiCell($this->w, $this->h_tab, $text_paiement, 0, 'L', 0); $this->PDF->Ln(); } //Affichage texte after if ($this->text_after != '') { $this->PDF->MultiCell($this->w, $this->h_tab, $this->text_after, 0, 'J', 0); $this->PDF->Ln(); } //Affichage signature $this->PDF->Ln(); $this->PDF->SetFontSize($this->fs_sign); $this->PDF->SetX($this->x_sign); $this->PDF->MultiCell($this->l_sign, $this->h_sign, $this->text_sign, 0, 'L', 0); }
//$abc = mysqli_query($con,$query); //$result = []; //while($result[] = mysqli_fetch_assoc($abc)); //foreach ($result as $val) { // if ($val['label'] == "Company"): // echo "<strong>".$val['label'] . "</strong><br>"; // else : // echo $val['label'] . "<br>"; // endif; // //var_dump($val); //} calc(2, 3); calc(2, 3); calc(2, 3); calc(2, 3); calc(2, 3); function calc($val, $val2) { global $paged; echo $paged; echo $val + $val2; } echo $xyz; $xyz = "sdfsf"; echo $xyz1(); $xyz1 = function ($val1) { echo $val1; }; for ($i = 0; $i <= 10; ++$i) { } $db = new COM();
} elseif ($action === 'умножить') { $too = $num1 * $num2; echo "<table border='1'>"; echo "<tr>"; echo "<td>" . $too . "</td>"; echo "</tr>"; echo "</table>"; } elseif ($action === 'разделить') { $mix = $num1 / $num2; echo "<table border='1'>"; echo "<tr>"; echo "<td>" . $mix . "</td>"; echo "</tr>"; echo "</table>"; } else { echo 'неправильно задано \'Действие\''; } } if (isset($_POST['num11'], $_POST['num12'], $_POST['action1'])) { calc($_POST['num11'], $_POST['num12'], $_POST['action1']); } ?> <h3>Форма</h3> <form method="post"> Значение 1: <div><input type="text" name="num11"></div> Значение 2: <div><input type="text" name="num12"></div> Действие : (плюс,минус,умножить,разделить) <div><input type="text" name="action1"></div> <div><input style="border-bottom-color: aqua","; type="submit" name="submit" value="Отправить"></div> </form>
$smarty->assign("searches", $searches); $sql = "select substring(post_time,1,10) as d ,count(*) as c from geobb_posts where post_time > '{$beginday}' AND post_time < '{$today}' group by substring(post_time,1,10)"; $sql2 = "select count(*) from geobb_posts"; $post = calc($sql, $sql2, 1000, 'Posts'); $smarty->assign("post", $post); $sql = "select substring(signup_date,1,10) as d ,count(*) as c from user where rights <> '' and signup_date > '{$beginday}' AND signup_date < '{$today}' group by substring(signup_date,1,10)"; $sql2 = "select count(*) from user where rights <> ''"; $users = calc($sql, $sql2, 500, 'Users'); $smarty->assign("users", $users); $sql = "select substring(signup_date,1,10) as d ,count(*) as c from user where rights <> '' and signup_date > '{$beginday}' AND signup_date < '{$today}' and (select gridimage_id from gridimage_search gi where gi.user_id = user.user_id {$andri} limit 1) is not NULL group by substring(signup_date,1,10)"; $sql2 = "select count(distinct user_id) from gridimage_search {$whereri}"; $cusers = calc($sql, $sql2, 100, 'Contributing Users'); $smarty->assign("cusers", $cusers); $sql = "select substring(submitted,1,10) as d ,count(*) as c from gridimage_search where ftf = 1 and submitted > '{$beginday}' AND submitted < '{$today}' {$andri} group by substring(submitted,1,10)"; $sql2 = "select count(*) from gridimage_search where ftf = 1 {$andri}"; $point = calc($sql, $sql2, 10000, 'Points'); $smarty->assign("point", $point); $total['average'] = $total['average_r'] = $point['total'] / ($days / 7); $total['next'] = $db->getOne("select count(*) from gridsquare where percent_land > 0 {$andri}"); $total['dif'] = $total['next'] - $point['count']; $total['weeks'] = $total['dif'] / $total['average']; $total['weeks_r'] = floor($total['weeks']); if ($total['weeks'] < 1040) { //20years $total['endtime'] = strtotime("+{$total['weeks_r']} weeks"); $total['enddate'] = "about " . date("F Y", $total['endtime']); } else { $total['enddate'] = "sometime in " . (date("Y") + round($total['weeks'] / 52)); } $smarty->assign("totall", $total); $smarty->assign_by_ref('references', $CONF['references_all']);
return f(function ($d, $s, $n) { return fconst($s, guard($n % $d === 0)); }, ...$args); } /* $tmp = f(function($n){ return fromMaybe($n, mappend(calc(3, "Fizz"), calc(5, "Buzz"), $n)); }); var_dump($tmp(9)); var_dump($tmp(10)); var_dump($tmp(11)); var_dump($tmp(15)); var_dump(fmap($tmp, range(1, 100))); */ $fizzbuzz = fromMaybe()->ap(mappend(calc(3, "Fizz"), calc(5, "Buzz"))); /* var_dump($fizzbuzz(9)); var_dump($fizzbuzz(10)); var_dump($fizzbuzz(11)); var_dump($fizzbuzz(15)); var_dump(fmap($fizzbuzz, range(1, 100))); */ function pr(...$args) { return f(function ($a) { echo $a, "\n"; return $a; }, ...$args); }
#!/usr/bin/env php <?php function factorial($n) { $res = 1; for ($i = 1; $i <= $n; $i++) { $res *= $i; } return $res; } function calc($n) { $res = 0; for ($i = 0; $i <= $n; $i++) { $res += 1 / factorial($i); } return $res; } $limit = 100; if ($argc > 1) { $limit = $argv[1]; } echo number_format(calc($limit), 16); echo "\n";
case 3: $result = $first / $second; $sing = '/'; break; case 4: $result = $first * $second; $sing = '*'; break; default: $result = null; } return array($result, $sing); } $print = null; if (!empty($_POST)) { $results = calc(); $errors = empty($validationErrors); if ($errors) { $print = $first . ' ' . $results[1] . ' ' . $second . ' = ' . $results[0]; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="reset.css"> <link rel="stylesheet" type="text/css" href="stylesheet.css"> <title>Task 1</title> </head> <body>
function exibe() { echo 'Olá Mundo<hr />'; } exibe(); function retorna() { return 'Olá Mundo<hr />'; } echo retorna(); function calc($valor, $percent) { $calc = $valor / 100 * $percent; return $calc; } echo calc(1500, 25) . '<hr />'; function formdate($data) { $data = explode('/', $data); $ano = $data[2]; $mes = $data[1]; $dia = $data[0]; return $ano . '-' . $mes . '-' . $dia . ' ' . date('H:i:s'); } echo date('d/m/Y H:i:s', strtotime(formdate('12/07/2015'))) . '<hr />'; function calcg($valorUm, $valorDois, $calc = '+') { if ($calc == '+') { return $valorUm + $valorDois; } elseif ($calc == '-') { return $valorUm - $valorDois;
$table[] = array(); if ($ismod) { $sql = "select count(*) from gridimage where moderator_id=" . $u; calc("Images Moderated", $sql); } $sql = "select count(*) from gridimage_ticket {$wherewhere}"; calc("Trouble Tickets Submitted", $sql); $sql = "select count(*) from gridimage_ticket_comment {$wherewhere}"; calc("Trouble Ticket Comments", $sql); if ($ismod) { $sql = "select count(*) from gridimage_ticket where moderator_id=" . $u; calc("Trouble Tickets Moderated", $sql); } $table[] = array(); $sql = "select count(*) from queries {$wherewhere}"; calc("Searches Performed", $sql); $smarty->assign_by_ref('table', $table); $smarty->assign("h2title", $title); $smarty->assign("nosort", 1); $smarty->assign("total", count($table)); } $smarty->display($template, $cacheid); function calc($name, $sql) { global $db, $table, $u, $u2; if ($u) { $val = $db->getOne($sql); } else { $val = $db->CacheGetOne(3600, $sql); } #if (!$val) return;
<div id="form"> <form name="bmi" method="post" action="bmi.php"> <h3 color:#93F3FF>Enter your information here</h3> <p> Enter your height: <input type="number" min="0" max="9" id="feet" name="feet">ft <input type="number" min="0" max="12" id="inch" name="inch">inches <p>Enter your weight: <input type="text" id="weight" name="weight"> <p><input type="submit" value="calculate" name="submit" onclick="return Validate()"> <input type= "reset" value="reset"> </form> </div> </form> <?php if (isset($_POST['submit'])) { calc(); } function calc() { $feet = $_POST['feet']; $inch = $_POST['inch']; $weight = $_POST['weight']; $height = $inch + 12 * $feet; $denom = pow($height, 2); $num = $weight / $denom; $bmi = $num * 703; echo "Your BMI is " . "<h4>" . round($bmi) . "</h4>"; if ($bmi < 18.5) { echo "You are underweight"; } elseif ($bmi <= 24.9) { echo "You have a healthy weight";
//計算處理過程 if (isset($_POST['num1']) and isset($_POST['num2']) and isset($_POST['class'])) { $numA = num($_POST['num1']); $numB = num($_POST['num2']); $class = $_POST['class']; //判斷是哪裡輸入錯誤或者哪裡輸入不正確 if ($numA == '輸入錯誤' or $numB == '輸入錯誤') { if ($numA == '輸入錯誤') { echo '<p class="label label-danger">第一個數字請重新輸入</p>'; } else { echo '<p class="label label-danger">第二個數字請重新輸入</p>'; } } elseif ($numB == 0 and $class == '/') { echo '<p class="label label-danger">除數不得為零</p>'; } else { $end = calc($class, $numA, $numB); echo '<h3><p class="label label-info">' . $numA . $class . $numB . '=' . $end . '</p></h3>'; } } function calc($class, $numA, $numB) { switch ($class) { case '+': $end = $numA + $numB; break; case '-': $end = $numA - $numB; break; case '*': $end = $numA * $numB; break;
<?php // сделать калькулятор 3 входящих параметра. 1 - число. 2-число. 3-действие (плюс минус умножить поделить) error_reporting(-1); header('Content-Type: text/html; charset=utf-8'); function calc($num1, $num2, $action) { } calc($_POST['num1'], $_POST['num2'], $_POST['action']); //получаем в функцию не обработанные данные из формы (если нужно обработать нада будет засовывать их в переменную и обрабатывать) ?> <form> <input type="text" name="num1"> <input type="text" name="num2"> <input type="text" name="action"> </form>
<?php function calc($num1, $num2 = 5, $type = false) { $result_mult = $num1 * $num2; $result_ruijyo = $result_mult * $result_mult; if ($type == false) { echo $result_mult; } else { echo $result_ruijyo; } $results = array($result_mult, $result_ruijyo); return $results; } $calc_results = calc(3, 5, false);
static function calcPaye($id_rubrique = 0, $wc = TRUE) { global $dbh; // Montant A valider pour une rubrique = // Somme des Montants pour les factures if ($wc) { $tab_r[$id_rubrique] = '1'; $tab_r = $tab_r + rubriques::getChilds($id_rubrique); $id_rubrique = implode("','", array_keys($tab_r)); } if (!$id_rubrique) { return array('ht' => 0, 'tva' => 0, 'ttc' => 0); } $q = "select "; $q .= "lignes_actes.nb as nb, lignes_actes.prix as prix, "; $q .= "lignes_actes.tva as tva, lignes_actes.remise as rem, lignes_actes.debit_tva "; $q .= "from actes, lignes_actes "; $q .= "where 1 "; $q .= "and actes.type_acte = '" . TYP_ACT_FAC . "' "; $q .= "and ((actes.statut & '" . STA_ACT_PAY . "') = '" . STA_ACT_PAY . "') "; $q .= "and lignes_actes.num_rubrique in('" . $id_rubrique . "') "; $q .= "and actes.id_acte = lignes_actes.num_acte "; $r = mysql_query($q, $dbh); $i = 0; $lg = array(); while ($row = mysql_fetch_object($r)) { $lg[$i]['q'] = $row->nb; $lg[$i]['p'] = $row->prix; $lg[$i]['t'] = $row->tva; $lg[$i]['r'] = $row->rem; $lg[$i]['debit_tva'] = $row->debit_tva; $i++; } $tot_rub = calc($lg, 2); return $tot_rub; }
<?php function calc($x, $y) { $z = $x * $y; echo "A rectangle of length {$x} and width {$y} has an area of {$z}. <br>"; } calc(5, 5); calc(10, 10);