title: How to use trim with array_map in PHP
body: <p>I am trying to remove two characters from the end of each line (if they exist) in an array map.</p>
  
  <p>These characters do not always exist</p>
  
  <p>So I am trying to convert </p>
  
  <pre class="lang-php prettyprint-override"><code>Array ( [0] =&gt; C7130A-B [1] =&gt; RB2-8120 [2] =&gt; RM1-1082-000B [3] =&gt; 0950-4768B [4] =&gt; C7130B )
  </code></pre>
  
  <p>to </p>
  
  <pre class="lang-php prettyprint-override"><code>Array ( [0] =&gt; C7130A [1] =&gt; RB2-8120 [2] =&gt; RM1-1082-000 [3] =&gt; 0950-4768 [4] =&gt; C7130 )
  </code></pre>
  
  <p>Basically I am trying to Eliminate B or -B from the end, I have found a way to do this on a string but cannot on an array.</p>
  
  <p>I have tried many options I have found here on Stack and have sadly had no luck.</p>
  
  <pre class="lang-php prettyprint-override"><code>function cleanit($s) {
      return rtrim($s, "B");
  }
  
  $words = strtoupper($words);
  $toBeFound = explode(PHP_EOL, $words);
  $war = array_map('cleanit', $toBeFound);
  echo('Begin&lt;br&gt;');
  print_r($war); 
  echo('&lt;br&gt;End');
  </code></pre>
  
  <p>So far the best result I have had is to remove the B (or -B) from the last item in the array. Which is the result of this code.</p>
  
  <pre class="lang-php prettyprint-override"><code>Array ( [0] =&gt; C7130A-B [1] =&gt; C7130B [2] =&gt; RM1-1082-000B [3] =&gt; 0950-4768B [4] =&gt; C7130 )
  </code></pre>