I am trying to remove two characters from the end of each line (if they exist) in an array map.
These characters do not always exist
So I am trying to convert
Array ( [0] => C7130A-B [1] => RB2-8120 [2] => RM1-1082-000B [3] => 0950-4768B [4] => C7130B )
to
Array ( [0] => C7130A [1] => RB2-8120 [2] => RM1-1082-000 [3] => 0950-4768 [4] => C7130 )
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.
I have tried many options I have found here on Stack and have sadly had no luck.
function cleanit($s) {
return rtrim($s, "B");
}
$words = strtoupper($words);
$toBeFound = explode(PHP_EOL, $words);
$war = array_map('cleanit', $toBeFound);
echo('Begin<br>');
print_r($war);
echo('<br>End');
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.
Array ( [0] => C7130A-B [1] => C7130B [2] => RM1-1082-000B [3] => 0950-4768B [4] => C7130 )