$str = 'i am a string';
$str = explode(' ', $str);
list($str[1], $str[3]) = [$str[3], $str[1]];
$str = implode(' ', $str);
print($str);
$text = 'СЧЕТУ 555 ОТ 01.01.2019, счету 556 ОТ 01.01.2019';
preg_match_all('/счету\s(\d+)\s/ui', $text, $matches);
print(implode(', ', $matches[1]));
$array = array_reduce($array, function($carry, $item) {
return $carry + $item;
}, []);
foreach($array as $key => $value ){
if (preg_match('/Red|Green|Black/', $key)) {
unset($array[$key]);
}
}
$array = ["zero", "one", "two", "three", "four"];
for (end($array); ($key = key($array)) !== null; prev($array) ) {
print($key . " : " . current($array) . "\n");
}
function diff($startTime, $endTime)
{
$startDate = new \DateTime($startTime);
$endDate = new \DateTime($endTime);
if ($startTime == $endTime) {
return 24;
}
if ($startDate >= $endDate) {
$startDate = $startDate->modify('-1 day');
}
$diff = $startDate->diff($endDate);
return $diff->h;
}
print(diff('05:00:00', '04:00:00'));
$text = 'Привет, тут какой-то другой текст';
var_dump(mb_substr($text, 8));
$text = 'Привет, тут какой-то другой текст';
preg_match('/^Привет, (.+)$/u', $text, $matches);
var_dump($matches[1]);
$array = array_map(function() {
return rand(1, 10);
},
array_fill(0, 10, null)
);
$resultArray = [];
foreach ($firstArray as $key) {
if (isset($secondArray[$key])) {
$resultArray[$key] = $secondArray[$key];
unset($secondArray[$key]);
}
}
$resultArray = array_merge($resultArray, $secondArray);