如何在while循环后对数组中的字符进行计数

时间:2012-04-06 05:18:57

标签: php loops count character

你是否有任何想法如何在while循环后计算字符串$chars中的所有字符?

$x = 0;
$b = 0;

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

echo strlen($chars);

1 个答案:

答案 0 :(得分:0)

连接字符然后计算它们

<?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
?>