Skip to content

Instantly share code, notes, and snippets.

View ArtemioVegas's full-sized avatar

Artyom Kotov ArtemioVegas

  • Bank 131
  • Armenia, Yerevan
View GitHub Profile
@ArtemioVegas
ArtemioVegas / Worker.php
Last active July 29, 2017 10:14
Задачи на ООП в PHP. Часть 1_1
<?php
class Worker{
private $name;
private $age;
private $salary;
public __construct()
@ArtemioVegas
ArtemioVegas / Driver.php
Created July 29, 2017 11:57
Задачи на ООП в PHP. Часть 1_2
<?php
class Driver extends NewWorker{
private $drivingExperience;
private $drivingCategory;
public function getDrivingExperience()
{
return $this->drivingExperience;
@ArtemioVegas
ArtemioVegas / Factorial.php
Last active September 7, 2017 14:12
Функция вычисления факториала - рекурсивная
<?php
function Factorial_Recursive($number){
$number = (int)$number;
if($number < 0){
return false;
}elseif($number >= 0 && $number <= 1 ){
return 1;
}else{
return $number * Factorial_Recursive($number - 1);
@ArtemioVegas
ArtemioVegas / check_array.php
Created September 8, 2017 08:33
* На входе массив чисел * array(2,5,3,5,6,7,8,9,25,24,18,26,27,28,29,30,31) * Вывести числа кратные 3 или 7 в строку разделенную запятыми
<?php
function check_array(array $arr){
$output = '';
foreach($arr as $element){
if($element != 0 && ($element %3 == 0 || $element %7 == 0)){
$output .= $element.',';
}
}
return substr($output, 0, -1);
@ArtemioVegas
ArtemioVegas / fibonacci.php
Created September 8, 2017 10:33
выводит последовательность чисел фибоначчи
<?php
/**
* Вывести числа Фибоначи, где кол-во цифр задано параметром $n
*
* На выходе строка к примеру - '0,1,1,2,3,5 и тд.'
*
* Числа Фибоначи где каждое последующее число
* образуется путем сложения двух предыдущих.
* Пример:
* 0,1
@ArtemioVegas
ArtemioVegas / max_array.php
Created September 8, 2017 11:17
Найти максимальное значение в одноуровневом массиве
<?php
/**
* Найти максимальное значение в одноуровневом массиве
* На входе array(2,5,3,5,6,7,8,9,25,24,18)
*
* Должно быть 333
*/
function testMinMax1(array $arr){
if($arr){
@ArtemioVegas
ArtemioVegas / min_array.php
Created September 8, 2017 11:18
* На входе массив чисел $array и число $min * Нам нужно удалить все значения, что меньше $min
<?php
/**
* На входе массив чисел $array и число $min
* Нам нужно удалить все значения, что меньше $min
*
* На входе array(2,5,3,5,6,7,8,9,25,24,18,26,27,28,29,30,31)
* Передаем $min = 9
* На выходе должно быть array(9,25,24,18,26,27,28,29,30,31)
*/
function testMinMax3(array $array, $min){
@ArtemioVegas
ArtemioVegas / counter.php
Created September 9, 2017 10:11
аналог встроенной пхп функции count
<?php
function counter(array $array,$multi = 0){
$count = 0;
foreach($array as $val){
if($multi){
if(is_array($val)){
$count += counter($val,1);
}else{
++$count;
@ArtemioVegas
ArtemioVegas / array_max.php
Last active September 9, 2017 10:27
Найти максимальное значение в многоуровневом массиве
<?php
/**
* Найти максимальное значение в многоуровневом массиве
* На входе array(1,2,array(400,12,13),3,4,array(21,22,23,array(231),),)
* На выходе 400
*/
function array_max($array)
{
static $max;
@ArtemioVegas
ArtemioVegas / cut_string.php
Created September 11, 2017 11:48
обрезать строку и добавить в конец '...', если та больше заданной длинны.
<?php
/**
* Нужно: обрезать строку и добавить в конец '...', если та больше заданной длинны.
*
* На входе два параметра
* $string - строка
* $lenght - длинна
*
* Пример:
* $tring = 'John Doe'