Re: array problems

From: Date: Fri, 28 Nov 2003 09:46:58 +0000
Subject: Re: array problems
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-171253@lists.php.net to get a copy of this message
Curtis Maurand wrote:
OK. That worked, thanks. Is it me, or is that rather odd behavior? It is you ;)
Shouldn't array elements set within a loop be available to me outside the loop if the loop exits normally? A loop is not a function (well it is, sort of.) Should I declare the variable as global? You are in a loop, so the variable is overwriten by new value in each iteration.
global $content_array; $city_found = 1; while(!feof ... When I was taking programming courses in college, I was taught that breaking out of a loop like that was bad practice; that it was better to leave a loop normally. Depends. You could write
$continue=true; while($continue && .. other conditions .. ) { if(... another condition ...) { .... $continue = false; } } I don't think this is any better then breaking out, and is certainly slower. break and continue constructs are here for a reason and the use is right here.
I've never programmed in "C" other than to write a crude little "dos2unix" (actually mac2dos) utility. Mosty i've written Perl, PHP Pascal and Basic. Pascal, Perl and Basic don't exhibit this behavior. All have this behavior.
I never worked with arrays in "C." Am I wrong?


« previous php.general (#171253) next »