April 6, 2012
How to count characters in array after while loop
Question by sdfgsdfg
Do u have any ideas how to count all characters in string $chars
after while loop ?
$x = 0;
$b = 0;
while ($x++ < 10) {
echo $chars = $item->zodziai[$b++];
echo ' ';
}
echo strlen($chars);
Answer by Starx
Concatenate the characters then count them
<?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
?>