Cainiao asks a simple logic question.

Source: Internet
Author: User
Cainiao asks a simple logic question.

I want to implement the 62 hexadecimal function, but the following code can only be echo and cannot be returned. I don't know why.

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 ($ )) {$ str = $ a [$ xs]. $ str; dwz ($ zs, $ str);} else {if ($ str = "") {return $ a [$ zs]. $ a [$ xs];} else {echo $ a [$ zs]. $ str; // only return $ a [$ zs] can be output here. $ str; // no value is returned. I don't know why.} for ($ I = 999990; $ I <= 1000000; $ I ++) {echo dwz ($ I); echo"
";}


Reply to discussion (solution)

Row 3 dwz ($ zs, $ str );
No response
$ Str = dwz ($ zs, $ str );

Return $ str is also required at the end of the function;

If ($ zs> = sizeof ($ a) {$ str = $ a [$ xs]. $ str; dwz ($ zs, $ str); // add return: return dwz ($ zs, $ str) here );}

Row 3 dwz ($ zs, $ str );
No response
$ Str = dwz ($ zs, $ str );

Return $ str is also required at the end of the function;

Haha, you can. thank you for your reminder and guidance.

This can also be written. reversible front-limit length

Echo convert_62 (999990); // 4C8secho convert_62 ('4c8s', 1); // 999990 function convert_62 ($ s, $ mode = 0) {$ d = str_split ('married'); $ r = ''; if ($ mode) {$ d = array_flip ($ d); for ($ I = 0; $ I
  
  

This can also be written. reversible front-limit length

Echo convert_62 (999990); // 4C8secho convert_62 ('4c8s', 1); // 999990 function convert_62 ($ s, $ mode = 0) {$ d = str_split ('married'); $ r = ''; if ($ mode) {$ d = array_flip ($ d); for ($ I = 0; $ I
     
    
Thank you.

This can also be written. reversible front-limit length

Echo convert_62 (999990); // 4C8secho convert_62 ('4c8s', 1); // 999990 function convert_62 ($ s, $ mode = 0) {$ d = str_split ('married'); $ r = ''; if ($ mode) {$ d = array_flip ($ d); for ($ I = 0; $ I
       
      

Sorry, could you tell me why I can test this file locally, but it cannot be used on the server? I will prompt that the function bcmod cannot be found.

Well, this is why the php_bc extension is not loaded (php for win is automatically loaded)
You can also check whether the php_gmp extension has been loaded. The same is true with this function library.

Well, this is why the php_bc extension is not loaded (php for win is automatically loaded)
You can also check whether the php_gmp extension has been loaded. The same is true with this function library.

I did not load it. what should I do?
I have no server permissions.

Print_r (get_loaded_extensions ());
Let's see what

Print_r (get_loaded_extensions ());
Let's see what

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)

If you have no permissions, you cannot do it.
Write it on your own, didn't you?

If you have no permissions, you cannot do it.
Write it on your own, didn't you?

The one I wrote is wrong. I found that the operation was followed by an error, and then I used your
I still haven't figured out where my mistake is. why is it wrong after the computation?
Thank you!

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;}


This is changed according to your prompt. it can be displayed, but my previous algorithm is wrong. Please check it out.

Now, thank you!

function dwz($s) {  $d = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ');  $r = '';  while($s) {$r = $d[(int)($s%62)].$r;$s = (int)($s/62);  }  return $r;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.