doufei4923 2019-08-05 12:11
浏览 264
已采纳

已解决的数组特殊字符到字符串

I am creating password generator, I am dealing at the moment with array of special characters to transfer them into string. I have special characters saved in cvs file, using as array to slice based on how many special characters should be in password, then I want to make them string and concatenate with numbers and letters.

    $list = './SpecialChar.csv';
    $e = array_map('str_getcsv', file($list));

    //$nRange telling how many characters should be slice
    $nRange = $length-($numb*2)-$specialChar;

    shuffle($e);
    $s = array_slice($e,0,$nRange);
    $sString = implode(" ",$s); //does not work
    $sString = htmlentities(implode(" ",$s)); //does not work
  • 写回答

1条回答 默认 最新

  • dphs48626 2019-08-05 12:44
    关注

    implode only accepts string so if you try to convert array to string this will return you "string(5) "Array"" no matter what it's in the array

    var_dump((string)["T","E","S","T"]);
    

    So when you try to implode multidimensional array you will get something like this

        $test = [["-"], ["*"]];
    var_dump(implode(" ", $test)); //THIS WILL GIVE YOU Notice: Array to string conversion when using implode , but it will return string(11) "Array Array"
    

    If dimensional are only two you can use array_map

    $test = [["-"], ["*"]];
    var_dump(implode(" ", array_map(function ($row) {
                            return is_array($row)?implode($row):$row;
                        }, $test))); //returns string(3) "- *"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog