K
K
koshelevsergey2018-04-01 15:49:30
PHP
koshelevsergey, 2018-04-01 15:49:30

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." мм подходящих танков не найдено.";
}

According to option 2 : How to output the same information but in a loop.
Code examples: {2 options}.
$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){

        }
    }
}

Or suggest your own option in this situation. I will certainly consider.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2018-04-01
@402d

studwork.org?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question