ЛБ6ЛиньковаКаспер - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of ЛБ6ЛиньковаКаспер.php
- <?php
- echo "Лабораторная №6. Пользовательские функции", "\n";
- echo "Задание 1", "\n";
- function SumKor($arr) {
- $sum = 0;
- foreach ($arr as $elem) {
- $sum += sqrt($elem);
- }
- return $sum;
- }
- $arr=[4, 16, 121, 1];
- echo SumKor($arr), "\n";
- echo "Задание 2", "\n";
- function DayWeek($val) {
- $arr = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вск"];
- if($val>0 and $val<8) {
- return $arr[$val - 1];
- }
- else {
- return "Wrong";
- }
- }
- $num = 4;
- echo DayWeek($num), "\n";
- echo "Задание 3", "\n";
- function getDivisors($num) {
- $div = [];
- for ($i = 1; $i <= $num; $i++) {
- if($num % $i == 0) {
- array_push($div, $i);
- }
- }
- return $div;
- }
- $res = getDivisors(14);
- foreach($res as $el) {
- echo $el. ' ';
- }
- ?>