jaunty_mellifluous Posted September 12, 2008 Share Posted September 12, 2008 Can you tell me why this code doesn't work? <?php $myarray = array('php', 'is', 'cool'); for($i = 0; $i < count($myarray); $i++) { echo "The value of index $i is: {$myarray[$i]} <br />\n"; ?> Quote Link to comment Share on other sites More sharing options...
akitchin Posted September 12, 2008 Share Posted September 12, 2008 try adding a closing brace to your for() statement. it's a syntax error. also, for the record, you would have an easier time using foreach(). if you need to use for() for whatever reason, you should put the count() statement out of the loop (and use a variable instead) since otherwise it has to run that function on every iteration. Quote Link to comment Share on other sites More sharing options...
jaunty_mellifluous Posted September 12, 2008 Author Share Posted September 12, 2008 thanks buddy .. is count() function only used to count all the elements in an array? Or are there any other uses for it? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 12, 2008 Share Posted September 12, 2008 That's all it's used for. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.