<?php
/* http://d...content-available-to-author-only...2.net/ */
SUBWAY => 'едешь на метро',
FOOT => 'идешь пешком',
BUS => 'едешь на автобусе'
);
$startPoint = 'pet'; // Петроградская
$endPoint = 'nov'; // Новая Голландия
'pet' => 'ст. м. Петроградская',
'chk' => 'ст. м. Чкаловская',
'gor' => 'ст. м. Горьковская',
'spo' => 'ст. м. Спортивная',
'vas' => 'ст. м. Василеостровская',
'kre' => 'Петропавловская крепость',
'let' => 'Летний сад',
'dvo' => 'Дворцовая площадь',
'isa' => 'Исакиевский собор',
'nov' => 'Новая Голландия',
'ras' => 'Дом Раскольникова',
'gos' => 'Гостиный Двор',
'sen' => 'Сенная Площадь',
'vla' => 'ст. м. Владимирская',
'vit' => 'Витебский вокзал',
'teh' => 'Технологический Институт'
);
'chk' => canGet(10, BUS),
'gor' => canGet(3, SUBWAY)
),
'pet' => canGet(10, BUS),
'spo' => canGet(3, SUBWAY)
),
'pet' => canGet(3, BUS),
'kre' => canGet(5, FOOT),
'gos' => canGet(6, SUBWAY)
),
'chk' => canGet(3, SUBWAY),
'vas' => canGet(10, BUS),
'sen' => canGet(7, SUBWAY)
),
'spo' => canGet(10, BUS),
'gos' => canGet(7, SUBWAY),
'nov' => canGet(11, FOOT)
),
'gor' => canGet(5, FOOT)
),
'dvo' => canGet(6, FOOT),
'gos' => canGet(7, FOOT)
),
'isa' => canGet(6, FOOT),
'gos' => canGet(6, FOOT),
'let' => canGet(6, FOOT)
),
'dvo' => canGet(6, FOOT),
'nov' => canGet(5, FOOT)
),
'vas' => canGet(11, FOOT),
'isa' => canGet(5, FOOT),
'ras' => canGet(7, BUS)
),
'nov' => canGet(7, BUS),
'sen' => canGet(3, FOOT)
),
'vas' => canGet(7, SUBWAY),
'sen' => canGet(3, SUBWAY),
'dvo' => canGet(6, FOOT),
'gor' => canGet(6, SUBWAY),
'let' => canGet(7, FOOT),
'vla' => canGet(7, FOOT)
),
'ras' => canGet(3, FOOT),
'spo' => canGet(7, SUBWAY),
'gos' => canGet(3, SUBWAY),
'vla' => canGet(4, SUBWAY),
'vit' => canGet(2, SUBWAY),
'teh' => canGet(3, SUBWAY)
),
'sen' => canGet(4, SUBWAY),
'gos' => canGet(7, FOOT),
'vit' => canGet(3, SUBWAY)
),
'sen' => canGet(2, SUBWAY),
'teh' => canGet(2, SUBWAY),
'vla' => canGet(3, SUBWAY)
),
'sen' => canGet(3, SUBWAY),
'vit' => canGet(2, SUBWAY)
)
);
/* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
«canGet» переводится как «можно попасть» */
function canGet($time, $byWhat) {
return array('time' => $time, 'by' => $byWhat); }
//print_r($paths);
function makeOneStep($paths, $pathDone, $time, $point, $target) {
$time += $paths[$point][$target]['time'];
$pathDone[] = $target;
$result = [];
$result['path'] = $pathDone;
$result['time'] = $time;
return $result;
}
}
$pathDone = array('teh', 'sen', 'gos'); $time = 6;
$point = 'gos';
$target = 'dvo';
$a = makeOneStep($paths, $pathDone, $time, $point, $target);
PD9waHAKCmVycm9yX3JlcG9ydGluZygtMSk7Ci8qIGh0dHA6Ly9kLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi4yLm5ldC8gKi8KCmRlZmluZSgnU1VCV0FZJywgJ3N1YicpOwpkZWZpbmUoJ0ZPT1QnLCAnZm9vdCcpOwpkZWZpbmUoJ0JVUycsICdidXMnKTsKCiR0cmFuc3BvcnROYW1lID0gYXJyYXkoCiAgICBTVUJXQVkgID0+ICAn0LXQtNC10YjRjCDQvdCwINC80LXRgtGA0L4nLAogICAgRk9PVCAgICA9PiAgJ9C40LTQtdGI0Ywg0L/QtdGI0LrQvtC8JywKICAgIEJVUyAgICAgPT4gICfQtdC00LXRiNGMINC90LAg0LDQstGC0L7QsdGD0YHQtScKKTsKCiRzdGFydFBvaW50ID0gJ3BldCc7IC8vINCf0LXRgtGA0L7Qs9GA0LDQtNGB0LrQsNGPCiRlbmRQb2ludCA9ICdub3YnOyAvLyDQndC+0LLQsNGPIN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ID0+ICAn0KLQtdGF0L3QvtC70L7Qs9C40YfQtdGB0LrQuNC5INCY0L3RgdGC0LjRgtGD0YInCik7CgokcGF0aHMgPSBhcnJheSgKICAgICdwZXQnICAgPT4gIGFycmF5KAogICAgICAgICdjaGsnICAgPT4gIGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnZ29yJyAgID0+ICBjYW5HZXQoMywgU1VCV0FZKQogICAgKSwKCiAgICAnY2hrJyAgID0+ICBhcnJheSgKICAgICAgICAncGV0JyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NwbycgICA9PiAgY2FuR2V0KDMsIFNVQldBWSkKICAgICksCgogICAgJ2dvcicgICA9PiAgYXJyYXkoCiAgICAgICAgJ3BldCcgICA9PiAgY2FuR2V0KDMsIEJVUyksCiAgICAgICAgJ2tyZScgICA9PiAgY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg2LCBTVUJXQVkpCiAgICApLAoKICAgICdzcG8nICAgPT4gIGFycmF5KAogICAgICAgICdjaGsnICAgPT4gIGNhbkdldCgzLCBTVUJXQVkpLAogICAgICAgICd2YXMnICAgPT4gIGNhbkdldCgxMCwgQlVTKSwKICAgICAgICAnc2VuJyAgID0+ICBjYW5HZXQoNywgU1VCV0FZKQogICAgKSwKCiAgICAndmFzJyAgID0+ICBhcnJheSgKICAgICAgICAnc3BvJyAgID0+ICBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ25vdicgICA9PiAgY2FuR2V0KDExLCBGT09UKQogICAgKSwKCiAgICAna3JlJyAgID0+ICBhcnJheSgKICAgICAgICAnZ29yJyAgID0+ICBjYW5HZXQoNSwgRk9PVCkKICAgICksCgogICAgJ2xldCcgICA9PiAgYXJyYXkoCiAgICAgICAgJ2R2bycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3MnICAgPT4gIGNhbkdldCg3LCBGT09UKQogICAgKSwKCiAgICAnZHZvJyAgID0+ICBhcnJheSgKICAgICAgICAnaXNhJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgICA9PiAgY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdsZXQnICAgPT4gIGNhbkdldCg2LCBGT09UKQogICAgKSwKCiAgICAnaXNhJyAgID0+ICBhcnJheSgKICAgICAgICAnZHZvJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ25vdicgICA9PiAgY2FuR2V0KDUsIEZPT1QpCiAgICApLAoKICAgICdub3YnICAgPT4gIGFycmF5KAogICAgICAgICd2YXMnICAgPT4gIGNhbkdldCgxMSwgRk9PVCksCiAgICAgICAgJ2lzYScgICA9PiAgY2FuR2V0KDUsIEZPT1QpLAogICAgICAgICdyYXMnICAgPT4gIGNhbkdldCg3LCBCVVMpCiAgICApLAoKICAgICdyYXMnICAgPT4gIGFycmF5KAogICAgICAgICdub3YnICAgPT4gIGNhbkdldCg3LCBCVVMpLAogICAgICAgICdzZW4nICAgPT4gIGNhbkdldCgzLCBGT09UKQogICAgKSwKCiAgICAnZ29zJyAgID0+ICBhcnJheSgKICAgICAgICAndmFzJyAgID0+ICBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnc2VuJyAgID0+ICBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAnZHZvJyAgID0+ICBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcicgICA9PiAgY2FuR2V0KDYsIFNVQldBWSksCiAgICAgICAgJ2xldCcgICA9PiAgY2FuR2V0KDcsIEZPT1QpLAogICAgICAgICd2bGEnICAgPT4gIGNhbkdldCg3LCBGT09UKSAgICAgICAgCiAgICApLAoKICAgICdzZW4nICAgPT4gIGFycmF5KAogICAgICAgICdyYXMnICAgPT4gIGNhbkdldCgzLCBGT09UKSwKICAgICAgICAnc3BvJyAgID0+ICBjYW5HZXQ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