菜鸟问个简单的逻辑问题,求解答
逻辑 菜鸟 简单的
我是想实现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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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











There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.
