Example #1
0
require_once 'pinyin/Pinyin.php';
$res = [['real_name' => 'ċ“ˆċ“ˆ', 'num' => 1], ['real_name' => 'oċ“ˆċ“ˆ', 'num' => 1]];
$sort = [];
$numsort = [];
$diffsort = [];
Pinyin::set('delimiter', '');
Pinyin::set('accent', false);
Pinyin::set('uppercase', true);
$dict = array();
foreach ($res as $value) {
    $workName = $value['real_name'];
    if (isset($dict[$workName])) {
        $value['pinyin'] = $dict[$workName]['pinyin'];
        $key = $dict[$workName]['key'];
    } else {
        $value['pinyin'] = Pinyin::trans($value['real_name']);
        $key = getFirstchar($value['pinyin']);
        $dict[$workName]['pinyin'] = $value['pinyin'];
        $dict[$workName]['key'] = $key;
    }
    $value['num'] = intval($value['num']);
    unset($value['value']);
    $id = $value['pinyin'];
    if ($key == '#') {
        if (isset($diffsort[$key][$id])) {
            $diffsort[$key][$id]['num'] = $diffsort[$key][$id]['num'] + $value['num'];
        } else {
            $diffsort[$key][$id] = $value;
        }
    } elseif ($key == '0-9') {
        if (isset($numsort[$key][$id])) {
Example #2
0
 public function getInfo($mysql)
 {
     $pinyin = Pinyin::trans($mysql["redword"]);
     var_dump($pinyin);
     echo "\n";
 }