Untitled

Run Settings
LanguagePHP
Language Version
Run Command
<?php function removeZeros($data) { $zero_idx = []; $last_non_zero = 0; foreach($data as $k => $v) { if ($v == 0) $zero_idx[] = $k; else $last_non_zero = $v; if ($v != 0 || $k == count($data) - 1) { foreach ($zero_idx as $i) $data[$i] = $last_non_zero; $zero_idx = []; } } return $data; } print_r(removeZeros([0, 0, 0, 0, 0, 0, 1])); print_r(removeZeros([2, 0, 0, 0, 0, 0, 0])); print_r(removeZeros([0, 3, 0, 4, 0, 5, 0]));
Editor Settings
Theme
Key bindings
Full width
Lines