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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.