<?php
//https://i...content-available-to-author-only...e.com/qQJDfQ
$tariffs = ['tariff0' => 0, 'tariff1' => 1,'tariff2' => 3,'tariff3' => 5];
$calls = [ [ "A-number" => "79222222222",
"B-number" => "79111111111",
"duration" => 127,
"tariff" => "tariff1"
],
[ "A-number" => "79111111111",
"B-number" => "79222222222",
"duration" => 53,
"tariff" => "tariff2"
],
[ "A-number" => "79222222222",
"B-number" => "79333333333",
"duration" => 671,
"tariff" => "tariff0"
],
[ "A-number" => "79333333333",
"B-number" => "79222222222",
"duration" => 632,
"tariff" => "tariff3"
],
[ "A-number" => "79111111111",
"B-number" => "79333333333",
"duration" => 331,
"tariff" => "tariff1"
]
];
function showCallsInfo($phoneNumber, $calls, $tariffs) {
$totalCost = 0;
$result = [];
foreach ($calls as $call) {
if ($call['A-number'] === $phoneNumber) {
$direction = 'исходящий';
$cost = $call['duration'] * $tariffs[$call['tariff']];
$totalCost += $cost;
} elseif ($call['B-number'] === $phoneNumber) {
$direction = 'входящий';
$cost = 0;
}
$result[] = [
'number' => $call['A-number'] === $phoneNumber ? $call['B-number'] : $call['A-number'],
'direction' => $direction,
'duration' => $call['duration'],
'tariff' => $direction === 'исходящий' ? $call['tariff'] : '',
'cost' => $cost
];
}
echo "Номер: $phoneNumber\n";
foreach ($result as $call) {
"%s %s %d сек. %s\n",
$call['number'],
$call['direction'],
$call['duration'],
$call['tariff']
);
}
}
showCallsInfo('79222222222', $calls, $tariffs);
PD9waHAKCi8vaHR0cHM6Ly9pLi4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5lLmNvbS9xUUpEZlEKCiR0YXJpZmZzID0gWyd0YXJpZmYwJyA9PiAwLCAndGFyaWZmMScgPT4gMSwndGFyaWZmMicgPT4gMywndGFyaWZmMycgPT4gNV07CgokY2FsbHMgPSBbIFsgIkEtbnVtYmVyIiA9PiAiNzkyMjIyMjIyMjIiLAoJCQkgIkItbnVtYmVyIiA9PiAiNzkxMTExMTExMTEiLAoJCQk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LknOwogICAgICAgICAgICAkY29zdCA9ICRjYWxsWydkdXJhdGlvbiddICogJHRhcmlmZnNbJGNhbGxbJ3RhcmlmZiddXTsKICAgICAgICAgICAgJHRvdGFsQ29zdCArPSAkY29zdDsKICAgICAgICB9IGVsc2VpZiAoJGNhbGxbJ0ItbnVtYmVyJ10gPT09ICRwaG9uZU51bWJlcikgewogICAgICAgICAgICAkZGlyZWN0aW9uID0gJ9Cy0YXQvtC00Y/RidC40LknOwogICAgICAgICAgICAkY29zdCA9IDA7CiAgICAgICAgfQogICAgICAgIAogICAgICAgICRyZXN1bHRbXSA9IFsKICAgICAgICAgICAgJ251bWJlcicgPT4gJGNhbGxbJ0EtbnVtYmVyJ10gPT09ICRwaG9uZU51bWJlciA/ICRjYWxsWydCLW51bWJlciddIDogJGNhbGxbJ0EtbnVtYmVyJ10sCiAgICAgICAgICAgICdkaXJlY3Rpb24nID0+ICRkaXJlY3Rpb24sCiAgICAgICAgICAgICdkdXJhdGlvbicgPT4gJGNhbGxbJ2R1cmF0aW9uJ10sCiAgICAgICAgICAgICd0YXJpZmYnID0+ICRkaXJlY3Rpb24gPT09ICfQuNGB0YXQvtC00Y/RidC40LknID8gJGNhbGxbJ3RhcmlmZiddIDogJycsCiAgICAgICAgICAgICdjb3N0JyA9PiAkY29zdAogICAgICAgIF07CiAgICB9CiAgICAKICAgIGVjaG8gItCd0L7QvNC10YA6ICRwaG9uZU51bWJlclxuIjsKICAgIAogICAgZm9yZWFjaCAoJHJlc3VsdCBhcyAkY2FsbCkgewogICAgICAgIGVjaG8gc3ByaW50ZigKICAgICAgICAgICAgIiVzICVzICVkINGB0LXQui4gJXNcbiIsCiAgICAgICAgICAgICRjYWxsWydudW1iZXInXSwKICAgICAgICAgICAgJGNhbGxbJ2RpcmVjdGlvbiddLAogICAgICAgICAgICAkY2FsbFsnZHVyYXRpb24nXSwKICAgICAgICAgICAgJGNhbGxbJ3RhcmlmZiddCiAgICAgICAgKTsKICAgIH0KICAgIAogICAgZWNobyAi0Jog0L7Qv9C70LDRgtC1OiAiIC4gbnVtYmVyX2Zvcm1hdCgkdG90YWxDb3N0LCAyKSAuICIg0YDRg9CxLlxuIjsKfQoKCnNob3dDYWxsc0luZm8oJzc5MjIyMjIyMjIyJywgJGNhbGxzLCAkdGFyaWZmcyk7Cg==