OK. That worked, thanks.
Is it me, or is that rather odd behavior? 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?
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. 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. I never worked with arrays in "C." Am
I wrong?
On Wednesday 26 November 2003 21:53, the council of elders heard Marek
Kilimajer mumble incoherently:
> Curtis Maurand wrote:
> > Sorry, its a typo. it should be:
> >
> > $city = "Ipswitch";
> > $city_found = 0;
> > $contentfile = fopen("content.txt", "r");
> > while (!feof($contentfile) && $city_found == 0);
> > {
> > $my_line = fgets($contentfile, 16384);
> > $content_array = explode("\t",$my_line);
> > if ($content_array[0] == $city)
> > {
> > $city_found = 1;
> > print("Matched on $content_aray[0]<br>\n");
>
> /* Break out of the while loop */
> break;
>
> > }
> > }
> > print("$content_array[0]\n");
> >
> > //end
> >
> > As I stated. The match happens and the "Matched on..." message
> > happens, but the print statement outside the "while" loop does
> > not. Its php-4.2.2 running on RedHat 8.0 (don't go there.) Its
> > the stock redhat php package. I don't trust redhat libraries for
> > building php from scratch. Of course, this might actually be the
> > problem, too. :-)
> >
> > Curtis
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php