Advertisement
rjangelov

StringsInPHP - //Problem 1. Removes Names

Jun 25th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. //Problem 1.    Removes Names
  2. //Write a script that takes as input two lists of names and removes from the first array all names given in the second array. The input //and output array are given as words, separated by a space, each list at a separate line. Examples:
  3. <!DOCTYPE html>
  4. <html>
  5.     <head>
  6.         <meta charset="UTF-8">
  7.         <title></title>
  8.     </head>
  9.     <body>
  10.         <form method="post" action="RemoveNames.php">
  11.             <input type="text" name="str1">
  12.             <input type="text" name="str2">
  13.             <input type="submit" value="GO">
  14.         </form>
  15.     </body>
  16. </html>
  17.  
  18. <?php
  19. $string1=$_POST['str1'];
  20. $string2=$_POST['str2'];
  21. $arr1 = explode(" ", $string1);
  22. $arr2 = explode(" ", $string2);
  23. $difference = array_diff($arr1, $arr2);
  24.  
  25. foreach($difference as $v){
  26.     echo $v.'&nbsp';
  27. }
  28.  
  29.  
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement