Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Первый вариант
- $run = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9);
- function cleaner($run)
- {
- $count_run = count($run);
- $last = $count_run-1;
- for ($z = 0; $z < $count_run; $z++)
- {
- if($z == $last && $run[$z] == 9)
- {
- unset($run[$z]);
- sort($run);
- // Здесь начинаем использовать рекурсию
- $run = cleaner($run);
- }
- }
- return $run;
- }
- $new_run = cleaner($run);
- ## Элегантный вариант
- for ($i = 0, $l = count($run) - 1; $i < $l; $i++) {
- if (end($run) === 9) {
- array_pop($run);
- --$i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement