-8

array = [1,2,3,4,5,3,2,3,1]

値を新しい配列に再配置します

SS (5), S (4), TP (3), TS (2), STS (1)

newarray =[sts,ts,tp,s,ss,tp,ts,tp,sts]

スイッチを使用してみましたが、正常に機能しませんでした。

どんな助けでも大歓迎です

4

3 に答える 3

3

PHP のNumberFormatterを調べてみてください。

$f = new NumberFormatter("en", NumberFormatter::SPELLOUT);
echo $f->format(123);

結果を生成します: 123

于 2013-07-03T09:19:54.400 に答える
0
$newArray = array_map(function ($num) {
    static $map = array(1 => 'one', /* more numbers here ... */);
    return $map[$num];
}, $array);

またはDeepuの提案を使用して:

$newArray = array_map(array(new NumberFormatter('en', NumberFormatter::SPELLOUT), 'format'), $array);
于 2013-07-03T09:21:47.447 に答える
0

PHP 5.3 以降を使用している場合は、上記の Deepu の回答を参照してください。

そうでない場合は、http://www.karlrixon.co.uk/writing/convert-numbers-to-words-with-php/を参照してください。

そのリンクを使用すると、配列をループして変換できます。

$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')
于 2013-07-03T09:20:34.767 に答える