Home  >  Q&A  >  body text

php - Numbers to text

How to quickly convert numbers into text
For example, 1 => one, 2=> two, ..., 15=》Fifteen
What I am currently thinking about is to save Chinese characters into a In array

$arr = ['一','二','三','四','五','六','七','八','九','十'];

But this is too troublesome
How to convert the input numbers into Chinese? Is there an easier way?

PHP中文网PHP中文网2709 days ago977

reply all(2)I'll reply

  • 代言

    代言2017-06-13 09:24:16

    Too free,,,,,,,,,,,,,,,,,,,,,,

    <?php
    
    $str = 1237124129124;
    
    //将一个字符串转换为数组
    $arr = str_split((string)$str,1);
    
    $cns = ['零','一','二','三','四','五','六','七','八','九'];
    
    foreach ($arr as $key) {
        echo $cns[$key];
    }
    
    //一二三七一二四一二九一二四

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-06-13 09:24:16

    Why not use key-value pairs

    $arr = [ 1=>'一', 2=>'二' ];

    reply
    0
  • Cancelreply