ロジックは初心者にとって簡単です
16 進数の関数を実装したいのですが、次のコードはエコーアウトされるだけで返されません。理由がわかりません。専門家に答えてくださいfunction dwz($id,$str=""){ $a=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $zs=(int)($id/sizeof($a)); $xs=$id%sizeof($a); if($zs>=sizeof($a)){ $str=$a[$xs].$str; dwz($zs,$str); } else{ if($str==""){ return $a[$zs].$a[$xs]; } else{ echo $a[$zs].$str;//这里只能输出 return $a[$zs].$str;//返回没值,不知道什么原因 } }}for($i=999990;$i<=1000000;$i++){ echo dwz($i); echo "<br>";}
7 行目 dwz($zs,$str);
return はありません
$str = dwz($zs,$str);
return $str が必要です関数の最後に
if($zs>=sizeof($a)){ $str=$a[$xs].$str; dwz($zs,$str); //这里加入return: return dwz($zs, $str); }
7 行目 dwz($zs,$str);
$str = dwz($zs,$str);
return $ が必要です。関数の最後に str;
はは、大丈夫です、ありがとう リマインダーとガイダンス
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
このように書くこともできます、リバーシブルのフロントは長さに制限はありません
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
楽しかったです、ありがとう
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
申し訳ありませんが、私が置いたときに機能する理由を教えてくださいこのファイルをテスト用にローカルに保存しましたが、サーバーに置くと機能しません。 bcmod 関数が見つからないというメッセージが表示されます
php_gmp 拡張機能が読み込まれているかどうかも確認できます。これはこの関数ライブラリでも同様です
あなたphp_gmp 拡張機能がロードされているかどうかも確認できます
本当にロードされていない場合はどうすればよいですか?
サーバーに権限がありません
何があるか見てみましょう
これがないと難しいです許可
ただ、自分で書いてください、あなたも書いたでしょう?私のエラーは、なぜ最後に計算が間違っているのかです
マスター、それを見るのを手伝ってください
Array( [0] => date [1] => libxml [2] => openssl [3] => pcre [4] => zlib [5] => ctype [6] => curl [7] => dom [8] => filter [9] => ftp [10] => gd [11] => hash [12] => iconv [13] => json [14] => mbstring [15] => mcrypt [16] => mhash [17] => mysql [18] => SimpleXML [19] => SPL [20] => PDO [21] => posix [22] => Reflection [23] => session [24] => pdo_sqlite [25] => sockets [26] => SQLite [27] => standard [28] => tokenizer [29] => xml [30] => xmlreader [31] => xmlwriter [32] => zip [33] => apache2handler [34] => memcache [35] => mssql [36] => soap [37] => Zend Optimizer)
やっとうまくいきました、神に感謝します
function dwz($id,$str=""){$a=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $zs=(int)($id/sizeof($a)); $xs=$id%sizeof($a); if($zs>=sizeof($a)){ $str=$a[$xs].$str; $str=dwz($zs,$str); } else{ if($str==""){return $a[$zs].$a[$xs];} else{return $a[$zs].$str;} } return $str;}