【问题标题】:How to count characters in array after while loop如何在while循环后计算数组中的字符
【发布时间】:2012-04-06 05:18:57
【问题描述】:

你知道如何在while循环之后计算字符串$chars中的所有字符吗?

$x = 0;
$b = 0;

while ($x++ < 10) {
  echo $chars = $item->zodziai[$b++];
  echo ' ';
}

echo strlen($chars);

【问题讨论】:

    标签: php loops count character


    【解决方案1】:

    连接字符然后计算它们

    <?php 
    $x = 0; $b = 0;
    $char = ''; //define a variable to collect all the chars
    while ($x++ < 10) {
       $char .= $item->zodziai[$b++]; //add to the char
       echo $chars = $item->zodziai[$b++]; echo ' ';
    }
    echo strlen($char); //then count all the array combined
    ?>
    

    【讨论】:

    • @JonasJovaisas,如果我的回答有效,请不要忘记接受它作为有效的解决方案(点击我回答左侧的小勾号)甚至投票。谢谢
    猜你喜欢
    • 2011-09-29
    • 2016-06-25
    • 1970-01-01
    • 2021-10-12
    • 2017-07-23
    • 2022-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多