菜鸟问个简单的逻辑问题,求解答
逻辑 菜鸟 简单的
我是想实现62进制的功能,可是下面这段代码只能echo出来,不能返回,不知道是什么原因,求高手解答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);
没有承接返回
$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_bc 扩展没加载的原因(php for win 是自动加载的)
你还可以检查一下 php_gmp 扩展是否已加载,用这个函数库也是一样的
嗯,这是 php_bc 扩展没加载的原因(php for win 是自动加载的)
你还可以检查一下 php_gmp 扩展是否已加载,用这个函数库也是一样的
真的没有加载,那怎么办啊?
我没服务器的权限
print_r(get_loaded_extensions());
看看都有些什么
print_r(get_loaded_extensions());
看看都有些什么
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;}
这是我根据你的提示改的,可以显示出来,但是我之前的算法有错,帮忙看下
终于可以了,谢谢大神
function dwz($s) { $d = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ'); $r = ''; while($s) { $r = $d[(int)($s%62)].$r; $s = (int)($s/62); } return $r;}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
