Re: Searching a file

From: Date: Sat, 22 May 2004 08:15:49 +0000
Subject: Re: Searching a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-186748@lists.php.net to get a copy of this message
"Ian Barnes" <ian@cerebellum.za.net> wrote in message news:DGEOIPPIAJBPINGMKMGKIEBIFLAA.ian@cerebellum.za.net... > Hi, > > [code] > $file=file("/ian/testing.file"); file://Load the file into array > unset($file[0]); file://Remove the first #gc line > foreach($file as $line){ // Run through each array line > $array[]=explode(",", $line); file://Separate each line in key/variable. > } > [/code] > > [code] > foreach($file as $line){ > if((in_array("1100", $line)) and (in_array("eth0", $line))){ > echo "Found eth0 and 1100 in array. Checkbox can be checked"; > }else{ > echo "Not found"; > } > } > [/code] Shouldn't you be looping through $array here (look at your first code sample at the top)?: foreach ($array as $subarray) { if (in_array('1100', $subarray) && in_array('eth0', $subarray)) { echo 'Found eth0 and 1100 in array. Checkbox can be checked'; } else { echo 'Not found'; } } Please try if it works. If so you could change all your foreach() loops to for() loops because you don't deal with associative arrays here and foreach creates copies of all values in memories. With for() you can directly acces the array values with $array[$i] etc. Regards, Torsten

« previous php.general (#186748) next »