R
R
Rouslan9432020-01-04 21:25:38
ruby
Rouslan943, 2020-01-04 21:25:38

How will this ruby ​​code be in php?

for i in (1..7).reverse_each do
    puts "Осталось #{i} секунд#{case i 
                                  when 2..4 then "ы" 
                                  when 1 then "а" 
                                  else "" 
                                end }..."
    sleep(1)
  end
  puts "Готово!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Poltorakov, 2020-01-04
​​@Rouslan943

<?php

        for ($i = 7; $i >= 1; $i--) {
            $ending = '';
            if ($i === 1) {
                $ending = 'a';
            } elseif ($i  >= 2 && $i <= 4) {
                $ending = 'ы';
            }
            echo "Осталось {$i} секунд{$ending} ...\n";
            sleep(1);
        }
        echo "Готово!";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question