Advertisement
alneoru

Заменить все нечетные числа в файле нулями

Apr 29th, 2016
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.39 KB | None | 0 0
  1.     //в файле числа 0 1 2 3 4 5 6 7 8 9 10 11 12
  2.     $chislas = file_get_contents('hotdogs.txt');
  3.     if($chislas!='') {
  4.         $chislar = explode(' ',$chislas); $newchislas='';
  5.         foreach($chislar as $key => $val) {
  6.             if( $val & 1) $newchislas .= '0 ';
  7.             else $newchislas .= $val.' ';
  8.         }
  9.         file_put_contents('hotdogs.txt',$newchislas);
  10.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement