Hey all, I am just playing with some basic PHP and I don't understand how this is counting my array, here is the code: <?php $names = array("Gobbly", "Loz", "Rayman"); $namesCount = count($names); print ($namesCount); ?> Code (markup): It returns 233 but I don't understand where it is getting that number from, I just wanted to count the amount of elements in my array. Any help would be much appreciated, thank you!
Use This: $namesCount = 0; $names = array("Gobbly", "Loz", "Rayman"); $namesCount = count($names); echo $namesCount; Code (markup): Chances are its in a loop or namesCount is somehow edited. I unit tested the above code and it gives 3. Peace,
The problem with the looping idea is that 233 is not divisible by 3. Unless you have something else adding to the $names array it most likely isn't a loop. Try this to see what's in the final array: <?php $names = array("Gobbly", "Loz", "Rayman"); echo "<pre>"; print_r($names); echo "</pre>"; //$namesCount = count($names); //print ($namesCount); ?> PHP:
Are you sure that ur script dosnt print other values before this one? Maybe u've forgot an echo or print somewhere.
What you see there is the entire script, it looks as though it is something to do with the strlen() function I am using as if I take that line away it returns the correct value. How would that strlen() function be causing it to return 233 I wonder?
hmm, i agree with the posts above, it's pretty straight forward so i cant see any reason why it doesnt work