I am writing some values into an array from a comma separated text file like this...
$tokenFile = "tokens.txt";
$tokenSet = file_get_contents($tokenFile);
$tokenValues = explode(',', $tokenSet);
foreach($tokenValues as $value) {
$tokens[] = "$value";
};
And I get this with print_r($tokens);
Array ( [0] => token1 [1] => token2 [2] => token3 )
This is all good and exactly what I want, I think, but then if I use in_array to check for one of those values I am not getting the results I want.
if (in_array('token2', $tokens)) {
echo "token found!";
};
If I create my $tokens array like below instead it works fine.
$tokens = array('token1', 'token2', 'token3')
And once again with print_r($tokens) I get..
Array ( [0] => token1 [1] => token2 [2] => token3 )
Both arrays appear exactly the same. What am I missing.
Update So the arrays are different
with var_dump I get the following array from the foreach loop
array(4) {
[0]=>
string(6) "token1"
[1]=>
string(8) "token2"
[2]=>
string(8) "token3"
}
And I get the this from the other array.
array(4) {
[0]=>
string(6) "token1"
[1]=>
string(6) "token2"
[2]=>
string(6) "token3"
}
var_dump($tokens);Right click -> view source code and show us what you get therestring(8) "token3"andstring(6) "token3"