dshnx48866 2018-10-24 12:26
浏览 113
已采纳

Echo在一行但在循环情况下

I have the following code:

$data  = ['a','b','c'];
$total = count($data);
for($i = 0; $i < $total; $i++) {
    echo $data;
}

What I need is when the code is running in cmd, the cmd will output each character so that it replaces the previous character in the display, like this:

enter image description here

a >> then changing to show b >> then changing to show c

...only in one line.

imagine that in line 3 of cmd will show the word alternately (a -> b -> c)

I have tried with "" but the result is nothing in cmd. Please can you help?

  • 写回答

3条回答 默认 最新

  • douxunzui1519 2018-10-24 12:42
    关注

    I suppose this is what you want. Correct me if I'm wrong. It first prints a, then replaces it with b, then replaces it with c.

    $data  = ['a','b','c'];
    $total = count($data);
    for($i = 0; $i < $total; $i++) {
        echo "\033[1D";      // Move 1 character backward
        echo $data[$i];  
        sleep(1);           // wait for a while, so we see the animation
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线