Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php function reverseNumber($n): void { $n = strval($n); echo substr($n, 1); echo $res; } reverseNumber(12345); die(); if(1 == '1') echo 'q'; if(true === 1) echo 'w'; if(true === 'true') echo 'e'; echo "\n"; /////////////// /* Задача: Напишите функцию, которая принимает массив чисел и возвращает массив с уникальными элементами, отсортированными в порядке убывания. Пример: Ввод: [4, 2, 9, 4, 2, 7] Вывод: [9, 7, 4, 2] */ $a = [4, 2, 9, 4, 2, 7]; function array_unique_sort($array) { rsort($array); $res = []; foreach($array as $item) { if(!in_array($item, $res)) array_push($res, $item); } return $res; } /////////// /* Задача: Напишите функцию, которая находит сумму всех элементов в многомерном массиве. Пример: Ввод: [[1, 2], [3,[4, 5]]] Вывод: 15 */ function func($arr) { $sum = 0; foreach ($arr as $elem) { if (is_array($elem)) { $sum += func($elem); } else { $sum += $elem; } } return $sum; } print_r(func([[1, 2], [3,[4, 5]]])); die(); /* Задача: Создайте класс Rectangle с методами для установки длины и ширины, а также для вычисления площади . */ Class Rectangle { protected int $width, $length; public function __construct() { $this->width = 1; $this->length = 1; } public function setWidth(int $a) { $this->width = $a; } public function setLength(int $a) { $this->length = $a; } public function getSquare() { return $this->width * $this->length; } } //////////// $a = 1; echo $a++; echo "<br />"; echo ++$a; /////////// class A{ function __construct(){ echo "A"; } } class B extends A{ function __construct(){ parent::__construct(); echo "B"; } } class C extends A{ function __construct(){ self::__construct(); echo "C"; } } class D extends A{ function __construct(){ echo "D"; } } $b = new B(); //ab + echo "<br />"; $c = new C(); //cc - echo "<br />"; $d = new D(); //d
Copy Clear