array = [1,2,3,4,5,3,2,3,1]
rearrange the value to new array
SS (5), S (4), TP (3), TS (2), STS (1)
newarray =[sts,ts,tp,s,ss,tp,ts,tp,sts]
i have try using switch but it did not work as it should.
any help would be greatly appreciated
If you are using PHP 5.3 or above, see Deepu's answer above.
If not, see http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/
Now using that link you could loop through your array and convert them.
$array = array(5,4,3,2,1,4,3,2);
$new = array();
foreach($array as $key => $value) {
$new[] = onvert_number_to_words($value);
}
print_r($new); // array = ('five','four','three','two','one','four','three','two')
Try looking into NumberFormatter for PHP.
$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format(123);
Produces the result: one hundred twenty-three
$newArray = array_map(function ($num) {
static $map = array(1 => 'one', /* more numbers here ... */);
return $map[$num];
}, $array);
Or using Deepu's suggestion:
$newArray = array_map(array(new NumberFormatter('en', NumberFormatter::SPELLOUT), 'format'), $array);