Re: array problems

From: Date: Fri, 28 Nov 2003 08:03:29 +0000
Subject: Re: array problems
Groups: php.general 
Request: Send a blank email to php-general+get-171248@lists.php.net to get a copy of this message
>$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"); > } > } >print("$content_array[0]\n"); I think what you got is a scope problem. You are creating $content_array in your while loop so its scope is limited to the while loop. To test this simply do a var_dump or print_r on $content_array outside your loop and see if it actually is an array, which I guess it won't it will either be null or an empty string. To solve simply do an initialisation of the variable before the while loop like $content_array = ''. Regards Stefan

« previous php.general (#171248) next »