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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!