douhu3424 2017-11-09 07:40
浏览 53
已采纳

如何将多个字符str_split index更改为一行字符str_split [duplicate]

This question already has an answer here:

I have this code:

$text = "12345678910";
$codebits = str_split($text ,3);
for($b = 0; $b<3; $b++){
  echo "$codebits[$b]yes";
}

which outputs the result:

123yes456yes789yes

How can I change it to be in one line? For example:

123456789yes
</div>
  • 写回答

2条回答 默认 最新

  • dongwalun2507 2017-11-09 07:43
    关注

    Use substr() like below:-

    <?php
    
    echo substr($text,0,8)."yes";
    

    Output:-https://eval.in/896033

    Or if you want to use your one:-

    <?php
    
    $text = "12345678910";
    $codebits = str_split($text ,3);
    for($b = 0; $b<3; $b++){
      echo "$codebits[$b]";
    }
    echo "yes";
    

    Output:- https://eval.in/896040

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码