duandou8120 2015-01-18 08:57
浏览 60

将JavaScript转换为PHP

I am new to PHP and I'm trying to convert a simple Javascript function into a PHP function. I need help converting this code to PHP. thanks so much

var intArrayToHexString = function(arr) {
              var hex = "";
              for (var i = 0; i < arr.length; i++) {
                if (arr[i] < 16)      
                hex += "0";
                hex += arr[i].toString(16);
              }
              return hex;
            };

PHP code: to php, this is what I've tried:

function intArrayToHexString($arr) {
              $hex = "";
              for ($i = 0; $i < strlen($arr); $i++) {
                if ($arr[$i] < 16)     
                $hex .= "0";
                $hex .= $arr[$i];
              }
              return $hex;
            };

PHP code does not work. Help me please.

  • 写回答

2条回答 默认 最新

  • dpmpa26468 2015-01-18 09:26
    关注

    In php you use '.' to concatinate in stead of a '+'

    $hex .= "0"; $hex .= $arr[$i];

    评论

报告相同问题?

悬赏问题

  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 UE5#if WITH_EDITOR导致打包的功能不可用
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面