<?php
function generateDatesRange($from, $to)
{
$from = new \DateTime($from);
$to = new \DateTime($to);
$start = new \DateTime($from->format('01.m.Y 00:00:00'));
$dates = [];
while ($start <= $to) {
$dates[] = $start->format('d.m.Y 00:00:00');
$dates[] = $start->format('t.m.Y 23:59:59');
$start->modify('+1 month');
}
$dates[0] = $from->format('d.m.Y H:i:s');
$dates[count($dates) - 1] = $to->format('d.m.Y H:i:s');
return array_chunk($dates, 2);
}
$from = '07.02.2019 22:10:56';
$to = '22.04.2019 19:22:35';
$result = generateDatesRange($from, $to);
print_r($result);
php index.php
Array
(
[0] => Array
(
[0] => 07.02.2019 22:10:56
[1] => 28.02.2019 23:59:59
)
[1] => Array
(
[0] => 01.03.2019 00:00:00
[1] => 31.03.2019 23:59:59
)
[2] => Array
(
[0] => 01.04.2019 00:00:00
[1] => 22.04.2019 19:22:35
)
)
php solution.php
Steps: 1 2 4 6 9
Values: 10 20 30 -100 100000
<?php
$k = 3;
$weight = [1 => 10, 20, -5, 30, -5, -100, -3000, -5000, 100000];
$n = count($weight);
$sum = [];
$comeFrom = [];
$sum[0] = 0;
$comeFrom[0] = 0;
for ($i = 1; $i <= $n; $i++) {
$comeFromIndex = $i - 1;
for ($j = max(0, $i - $k); $j <= ($i - 1); $j++) {
if ($sum[$j] > $sum[$comeFromIndex]) {
$comeFromIndex = $j;
}
}
$sum[$i] = $sum[$comeFromIndex] + $weight[$i];
$comeFrom[$i] = $comeFromIndex;
}
$steps = [];
while ($n) {
$steps[] = $n;
$n = $comeFrom[$n];
}
echo 'Steps: ' . implode(' ', array_reverse($steps));
echo "\n";
echo 'Values: ' . implode(' ', array_intersect_key($weight, array_combine($steps, $steps)));
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
$url= 'https://www.mos.ru/altmosmvc/api/v1/taxi/getInfo/?Region=Москва&RegNum=&FullName=&LicenseNum=&Condition=&pagenumber=1';
$client = new Client([
'base_url' => $url,
'cookies' => CookieJar::fromArray(['mos_id' => 'CllGx1yOW5nBYizxkxtbAgA='], '.mos.ru'),
'allow_redirects' => true,
'decode_content' => true
]);
$response = $client->request('get', $url);
echo $response->getBody()->getContents();
Веб-сервер выполняет только один однопоточный процесс, поэтому приложения PHP будут останавливаться, если запрос заблокирован.
/**
* @Route("/api", name="api")
*/
public function apiAction()
{
sleep(10);
return new Response('API page');
}
/**
* @Route("/test", name="test")
*/
public function testAction()
{
return new Response('Test page');
}
<div>
<iframe src="{{ path('elfinder', {'instance': 'default', 'homeFolder': ''}) }}" style="width: 100%;height: 400px;"></iframe>
</div>
<div>
{{ render(controller('\\FM\\ElfinderBundle\\Controller\\ElFinderController::showAction', {'instance': 'default', 'homeFolder': ''})) }}
</div>