adam_gardner Posted April 11, 2006 Share Posted April 11, 2006 hi guys,what i want to do is use an if - else to compare a variable to a load of variables. I could of course use an OR, but i've got about 200 variable to compare -- long loop!what i want to do is compare it to a files content - so for example i have a file called [b]compare.txt[/b]my compare.txt file has the lines - abcde(etc.)so (pseudocode) - $myvariable='f'if $myvariable == compare.txt variables[i]do something[/i]else[i]do something else[i]so in this case it would return falseis there a way to do this or would i have to list a,b,c & d as seperate variables?thanks for the help!Adam Link to comment https://forums.phpfreaks.com/topic/7118-compare-values-in-a-file/ Share on other sites More sharing options...
kenrbnsn Posted April 11, 2006 Share Posted April 11, 2006 Try this:[code]<?php$compare = file('compare.txt')$var = 'f';if (in_array($var."\n",$compare)) echo 'Variable ' . $var. ' found';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/7118-compare-values-in-a-file/#findComment-25885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.