title: How to remove everything after a space in each of my array objects in PHP?
body: <p>I have two arrays containing letters and numbers for each array object. example: &quot;Matthew 20897&quot;. I want to delete the numbers from every array object so I can compare both arrays and see if they have any words/names in common. I tried doing an explode to get rid of the space but I get an error saying the explode() expects parameter 2 to be a string.</p>
  <p>Below is the code I have so far:</p>
  <pre><code>&lt;?php
  //simple read file and print
  $boy = array();
  $girl = array();
  $connectionBoy = fopen(&quot;boynames.txt&quot;, &quot;r&quot;) or die(&quot;Can't open boynames.txt file.&quot;);
  $connectionGirl = fopen(&quot;girlnames.txt&quot;, &quot;r&quot;) or die(&quot;Can't open girlnames.txt file.&quot;);
  
  while(! feof($connectionBoy)){   //while it is not the end of the file
      
      $word = fgets($connectionBoy);  //read a record
      $word = rtrim($word); //gets rid of end of record char
      $boy[] = $word;
  }
  
  while(! feof($connectionGirl)){   //while it is not the end of the file
      
      $word2 = fgets($connectionGirl);  //read a record
      $word2 = rtrim($word2); //gets rid of end of record char
      $girl[] = $word2;
  }
  
  fclose($connectionBoy);
   echo &quot;Number of names in the boynames file are &quot;.sizeof($boy).&quot;&lt;br&gt;&quot;;
   echo &quot;Number of names in the boynames file are &quot;.sizeof($girl);
   
   $itemBoy = explode(&quot; &quot;,$boy);
   $itemGirl = explode(&quot; &quot;,$girl);
   
   $result =array_intersect($itemBoy,$itemGirl);
   print_r($result);
  </code></pre>
  <p>Also, both arrays have 1000 records stored in them so I would have to remove everything after the space for all items in both arrays.</p>