0

你有什么想法如何$chars在while循环之后计算字符串中的所有字符吗?

$x = 0;
$b = 0;

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

echo strlen($chars);
4

1 回答 1

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
?>
于 2012-04-06T05:21:52.813 回答