 
  
   
  
   
  
  Как добиться такого, чтоб можно было делать объект класса без параметра?
когда делаешь объект какого-то класса, то можно не передавать ему параметры. А в самом классе конструктор может быть с параметрами
class MyClass {
    
    public $param;
    public $actionRepository;
    
    public function __construct(?ActionRepository $actionRepository = null, $param= null)
    {
        $this->actionRepository = $actionRepository;
        $this->param = $param;
    }
}
$myClass = new MyClass(); 
  
   
  
  <?php
$format = 'Год: Y, Месяц: m, День: d';
$dates = [new DateTime('2020-10-20'), new DateTime('2000-02-05'), new DateTime('2000-02-02'), new DateTime('2000-05-01')];
usort($dates, fn($a, $b) => $a < $b ? -1: 1);
//Самая ранняя будет: $dates[0]->format($format);
foreach($dates as $date) {
    var_dump($date->format($format)); 
}
var_dump('Min: ' . $dates[0]->format($format));
var_dump('Max: ' . $dates[count($dates) - 1]->format($format));string(42) "Год: 2000, Месяц: 02, День: 02"
string(42) "Год: 2000, Месяц: 02, День: 05"
string(42) "Год: 2000, Месяц: 05, День: 01"
string(42) "Год: 2020, Месяц: 10, День: 20"
string(47) "Min: Год: 2000, Месяц: 02, День: 02"
string(47) "Max: Год: 2020, Месяц: 10, День: 20" 
  
  const services = [
     	{name: 'Дизайн и визуализация', active: $('#designVisual').prop('checked')},
        {name: 'Рабочий проект', active: $('#workSpace').prop('checked')},
        {name: 'Строительство', active: true}
];
const activeService = services.find(service => service.active == true);
const msg = {
    'Имя: ':  $('#call-name').val(),
    'Телефон: ':  $('#call-tel').val(),
};
msg['Услуга: '] = activeService.name;
$.post('post.php', msg, function() {
   $('.call-me__wrap').hide()
   $('.call-me__complete').show()
}); 
  
   
  
   
  
  <?php
function getColors($item_colors, $result = []){
    preg_match_all('/(\w+),|(\w+)\/(\w+)/', $item_colors, $colors);
    foreach ($colors as $key => $value) {
        if ($key === 0) continue;
        array_push($result, ...$value);
    }
    return array_filter($result);
}
$item_colors = "Vario Base Unit with steel, large, black/orange";
echo implode(' ', getColors($item_colors));
//steel large black orange
var_dump(getColors($item_colors));
// array(4) {
//   [0]=>
//   string(5) "steel"
//   [1]=>
//   string(5) "large"
//   [5]=>
//   string(5) "black"
//   [8]=>
//   string(6) "orange"
// }<?php
$item_colors = "Vario Base Unit with steel, large, black/orange";
$result = [];
foreach (explode(', ', str_replace('Vario Base Unit with ','', $item_colors)) as $color) {
    $colors = explode('/', $color);
    count($colors) === 2 ? array_push($result, ...$colors) : array_push($result, $color);
}
echo implode(' ', $result);
//steel large black orange
var_dump($result);
// array(4) {
//   [0]=>
//   string(5) "steel"
//   [1]=>
//   string(5) "large"
//   [2]=>
//   string(5) "black"
//   [3]=>
//   string(6) "orange"
// }<?php
$item_colors = "Vario Base Unit with steel, large, black/orange";
$result = eval('return '.str_replace(['Vario Base Unit with ', '/', ', '], ['["',', ', '", "'], $item_colors).'"];');
echo implode(' ', $result);
//steel large black orange
var_dump($result);
// array(4) {
//   [0]=>
//   string(5) "steel"
//   [1]=>
//   string(5) "large"
//   [2]=>
//   string(5) "black"
//   [3]=>
//   string(6) "orange"
// } 
  
   
  
  <?php
class KeysReplacer {
    public $default = [
        'id' => 'id',
        'full_address' => 'adress',
        'floorall' => 'floorall',
        'build_year' => 'build_year',
    ];
    public $services = [
        'service_1' => [
            'id' => 'internal_id',
            'full_address' => 'locality',
            'floorall' => 'floorall',
            'build_year' => 'build_date'
        ],
        'service_2' => [
            'id' => 'ид',
            'full_address' => 'полный_адрес',
            'floorall' => 'этажность',
            'build_year' => 'год_постройки'
        ],
    ];
    
    
    public function __invoke($item, $from = null)
    {
       $result = [];
            foreach($item as $key => $value){
                $result[$from && isset($this->services[$from][$key])
                ? $this->services[$from][$key]
                : $this->default[$key]] = $value;
            }
        return json_encode($result, JSON_UNESCAPED_UNICODE);
    }
}
function getItem(){
    return [
        'id' => 1,
        'full_address' => 'г. Москва',
        'floorall' => 18,
        'build_year' => 1990
    ];
}
$item = getItem();
$responseNormalizer = new KeysReplacer;
$response_0 = $responseNormalizer($item);
$response_1 = $responseNormalizer($item, 'service_1');
$response_2 = $responseNormalizer($item, 'service_2');
var_dump($response_0); // string(68) "{"id":1,"adress":"г. Москва","floorall":18,"build_year":1990}"
var_dump($response_1); // string(79) "{"internal_id":1,"locality":"г. Москва","floorall":18,"build_date":1990}"
var_dump($response_2); // string(112) "{"ид":1,"полный_адрес":"г. Москва","этажность":18,"год_постройки":1990}" 
  
  $arrays = [
    ['hello' => 'world 0', 1, 2, 3, 4],
    ['hello' => 'world 1'],
    ['hello' => 'world 2', 5, 6, 7],
    ['hello' => 'world 3', 5, 6, 7, 8, 9]
];
$newArray = array_reduce($arrays, function ($carry, $item) {
    if (isset($item['hello']) && $item['hello'] === 'world 2' || $item['hello'] === 'world 0') {
        $carry = array_merge($carry, $item);
    }
    return $carry;
}, []);array(8) {
  ["hello"]=>
  string(7) "world 2"
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
  [3]=>
  int(4)
  [4]=>
  int(5)
  [5]=>
  int(6)
  [6]=>
  int(7)
}