Guest User

php-function

a guest
Jul 31st, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2.         if(isset($_GET['commands']) && isset($_GET['delimiter']))
  3.         {
  4.             $input = $_GET['commands'];
  5.             $delimiter = $_GET['delimiter'];
  6.  
  7.             $arr = explode("\n", $input);
  8.             $arr = array_map('trim', $arr);
  9.             $arrResult = array();
  10.  
  11.             for($i = 0; $i < count($arr); $i++)
  12.             {
  13.                 $line = explode($delimiter, $arr[$i]);
  14.                 $command = $line[0];
  15.                 $value = intval($line[1]);
  16.  
  17.                 if($command == "add")
  18.                     $arrResult[] = $value;
  19.  
  20.                 else
  21.                     array_splice($arrResult, $value, 1);
  22.             }
  23.  
  24.             foreach($arrResult as $element)
  25.             {
  26.                 echo $element. "<br>";
  27.             }
  28.         }
  29.     ?>
Advertisement
Add Comment
Please, Sign In to add comment