global $tal; $tal = $tal * 2; return $tal; } ?> <!DOCTYPE html> <html lang="sv"> <head> <meta charset="utf-8"> <title></title> <link rel="stylesheet" href=""> </head> <body> <?php /* Använder funktionen */ fetstil(); fetstil("Karim Ryde", "blue"); fetstil("Funktioner fungerar ungefär som ett snabbkommando för att göra en lång lista av kommandon i ett svep. Därmed slipper man upprepa kod i programmet, vilket gör det lättare att skriva och uppdatera. Förutom de många funktioner som php har inbyggt, kan man alltså skapa egna funktioner.", "pink"); fetstil("Tomte", "mistyrose", 25); echo "<p>" . areaCirkel(5) . "</p>"; echo "<p>" . summa(5, 7) . "</p>"; echo "<p>" . summa2([2, 3, 6, 8, 9]) . "</p>"; echo "<p>" . dubbel(6) . "</p>"; $tal = 3; echo "<p>" . dubbel(6) . "</p>"; $tal = 6; echo "<p>" . dubbel2() . "</p>"; ?> </body> </html>
//идем по каждому элементу массива if ($array[$i] == is_float($array[$i]) || $array[$i] == is_int($array[$i])) { //проверяем тип элемента $summ = $summ + $array[$i]; } } return $summ; // возвращает суму всех чисел } else { return 'does not work'; } } //Vars $myArray = array(26, 2.35, 'hello', 117, 89, 56, 75.08); $myString = 'Just for testing'; echo 'Сумма всех чиcел массива: ' . summa($myArray) . '.'; ?> </div> </div> </section> <section class="container"> <h2>Exercise 7</h2> <div class="row"> <div class="col-xs-12 col-md-2"> <h4>Задание:</h4> </div> <div class="col-xs-12 col-md-10"> <p>Напишите функцию, которая принимает одномерный массив следующего вида:</p> <code>array(<br> 'index.php' => 'Home',<br>
<?php /** * JBZoo PHPUnit * * This file is part of the JBZoo CCK package. * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @package PHPUnit * @license MIT * @copyright Copyright (C) JBZoo.com, All rights reserved. * @link https://github.com/JBZoo/PHPUnit * @author Denis Smetannikov <*****@*****.**> */ /** * @param float $a * @param float $b * @return mixed */ function summa($a, $b) { return $a + $b; } echo 'Some text message'; return summa(2, 3);
if (isset($row['sum'])) { $v = gmp_init($row['sum']); $total_in = gmp_add($total_in, $v); } $total_in = gmp_strval($total_in); $total_out = gmp_init('0'); $query = "\n SELECT SUM(amount) AS sum\n FROM requests\n WHERE curr_type='{$type}' AND req_type='DEPOS' AND status='FINAL'\n "; $result = do_query($query); $row = get_row($result); if (isset($row['sum'])) { $v = gmp_init($row['sum']); $total_out = gmp_add($total_out, $v); } $query = "\n SELECT SUM(amount) AS sum\n FROM requests\n WHERE curr_type='{$type}' AND req_type='WITHDR' AND status='FINAL'\n "; $result = do_query($query); $row = get_row($result); if (isset($row['sum'])) { $v = gmp_init($row['sum']); $total_out = gmp_sub($total_out, $v); } $total_out = gmp_strval($total_out); echo "{$type} = {$total_in}\t {$total_out}\n"; if (gmp_cmp($total_in, $total_out) != 0) { echo "*********** MISMATCH ****************\n"; } } summa('BTC'); summa(CURRENCY); ?>