By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

how while loop value prints outside loop

P: 17
Expand|Select|Wrap|Line Numbers
  1. while (false !== ($sfname = readdir($dh))) {
  2.   if (substr($sfname, 0, 1) == '.') continue;
  3.   if ($sfname == 'CVS'            ) continue;
  4.   $sitedir = "$OE_SITES_BASE/$sfname";
  5.   if (!is_dir($sitedir)               ) continue;
  6.   if (!is_file("$sitedir/sqlconf.php")) continue;
  7.   $siteslist[$sfname] = $sfname;
  8.     }    echo $sfname;//here not prints sfname value
the value not prints outside the loop. please help me
Apr 12 '12 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,584
You can't print a variable in the scope of the while loop outside it's scope, outside the while loop.

Your code iterates through the while loop and prints the last value that was assigned to $sfname.
Apr 12 '12 #2

P: 1,059
@dilite922 I am confused about the information of while loop scope.
as far I know, while loop, if statement don’t have their own scope.

but about ditditsasa's problem, if the while condition does not satisfy in the first place in your print you won’t get anything.
Apr 13 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.