Sometimes answering these require noted caveats, so here are mine.
[1] I'm assuming all the values in the array would be percentages, so I dropped that out of my starting array, and appended them when I printed the string.
[2] I'm allowing for a positive or negative sign at the beginning of each element.
[3] I'm expecting the number value to be a whole number (I'm assuming you want the alignment as you had in your question, where each value takes up two spaces)
If any of these assumptions are incorrect, the code below would need to be modified to account for the changes.
<?php
$arrPercentages = array('+9','+12','+1');
foreach($arrPercentages as $strPercentage) {
// Get rid of any spaces
$strPercentage = str_replace(' ', '', $strPercentage);
// Parse out the number
preg_match('/([\-\+]{1})([0-9]+)/', $strPercentage, $arrMatches);
// Don't continue if we didn't get a sign and number out of the string
if(count($arrMatches)) {
// Assign the "sign" to a variable
$strSign = $arrMatches[1];
// The number we want to print out as two character spaces
$strNumber = $arrMatches[2];
// Print it out!
echo $strSign.sprintf("%2s", $strNumber).'%<br>';
}
}
?>