Answer the question
In order to leave comments, you need to log in
Who can help complete the PHP code?
Good afternoon!
There is such a task: prntscr.com/iz9omm
And its execution in 2 versions:
1) prntscr.com/iz9q1x
2) prntscr.com/iz9s7i
The essence of the question is this:
Which option is better to do and how?
According to option 1 : How to make it so that the speed of the tanks is displayed?
where it should be written.
Code examples: {1 variants}.
$tableTanks = [
'TP-41' => [80,10],
'TP-32' => [60,20],
'TSH-605' => [90,5],
'TSH-607' => [90,7],
'TT-22' => [40,20],
'TT-25' => [40,50]
];
$armor = [2,7,5,15,30,1,54,12,61];
$rand = array_rand($armor,2);
$rand_2 = $armor[$rand[0]];
arsort($tableTanks);
$tanksResult = array_keys(
array_filter($tableTanks,
function ($row)use($rand_2){
return $row[1] >= $rand_2;
})
);
echo "<br><br>";
if ($tanksResult[1]) {
echo "Чтобы пробить броню толщиной ".$rand_2." мм подойдет любой танк этой марки: ".implode(', ', $tanksResult).", со скоростью перемещения ХХ км/ч^.";
} elseif ($tanksResult[0]) {
echo "Чтобы пробить броню толщиной ".$rand_2." мм нужен танк марки: ".implode(', ', $tanksResult).", со скоростью перемещения ХХ км/ч^.";
} else {
echo "Чтобы пробить броню толщиной ".$rand_2." мм подходящих танков не найдено.";
}
$tableTanks = [
'TP-41' => [80,10],
'TP-32' => [60,20],
'TSH-605' => [90,5],
'TSH-607' => [90,7],
'TT-22' => [40,20],
'TT-25' => [40,50]
];
$armor = [2,7,5,15,30,1,54,12,61];
$suitableTank = [];
sort($suitableTank);
foreach ($armor as $inx => $parametrs){
$suitableTank = [];
foreach ($tableTanks as $name => $armor){
if ($parametrs <= $armor[1]) {
$suitableTank[$name] = $armor[0];
} else {
}
}
arsort($suitableTank);
foreach ($suitableTank as $name => $speed) {
if ($parametrs == 1 and count($suitableTank) > 1){
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question