shachi
08-19-2006, 04:58 PM
Hello,
I am simply trying to see if a value exists in an array of external file read by the file() function but unfortunately neither the in_array function is working nor the search_array. My code looks like this.
<?php
//$arr = array('red', 'green', 'blue');
$arr = file('colors.txt');
if(in_array('green',$arr)){
echo "Fount at index:".in_array('green',$arr);
} else {
echo "Not found";
}
?>
txt file, colors.txt
red
green
blue
green
It works with the arrays created with the array function but not with the file function any help would be appreciated. Thanks.
I am simply trying to see if a value exists in an array of external file read by the file() function but unfortunately neither the in_array function is working nor the search_array. My code looks like this.
<?php
//$arr = array('red', 'green', 'blue');
$arr = file('colors.txt');
if(in_array('green',$arr)){
echo "Fount at index:".in_array('green',$arr);
} else {
echo "Not found";
}
?>
txt file, colors.txt
red
green
blue
green
It works with the arrays created with the array function but not with the file function any help would be appreciated. Thanks.