Advertisement
braveheart1989

05. Add/Remove Elements1

Jul 4th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_GET['commands'])&&isset($_GET['delimiter'])){
  4.  
  5.     $command= $_GET['commands'];
  6.     $delimiter = $_GET['delimiter'];
  7.     $command = explode("\n", $command);
  8.     $command = array_map('trim', $command);
  9.  
  10.     $result=[];
  11.  
  12.     for($i=0; $i<count($command); $i++){ // sizeof-count
  13.  
  14.         $parts = explode($delimiter, $command[$i]);
  15.         $key  = $parts[0];
  16.         $value  = $parts[1];
  17.         if($key == "add"){
  18. //            $result[$i] = $parts[1];
  19.             array_push($result,$value);
  20.         }
  21.         else{
  22.             array_splice($result,$value,1);
  23.         }
  24.  
  25. //        if($parts[0] == "add"){
  26. //            $result[$i] = $parts[1];
  27. //        }
  28. //        else if($parts[0]== "remove"){
  29. //            array_splice($result,$parts[1],1);
  30. //        }
  31.  
  32.     }
  33.  
  34.     for($i=0; $i<count($result); $i++){
  35.         echo $result[$i]."<br>";
  36.     }
  37. //    for($i=0; $i<sizeof($result); $i++){
  38. //        echo $result[$i]."<br>";
  39. //    }
  40.    
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement