Friday, May 11, 2018

PHP != and == operators

This has boggled me for a while. I am running through a directory and echo'ing out its contents, and I want to exclude the ".." and "." files.



Now, this code works:



if ($files = scandir("temp/"))
{
foreach ($files as $file)
{

if ($file == ".." OR $file == ".")
{
}
else {
echo $file;
echo "
";
}
}
}



But this doesn't...



if ($files = scandir("temp/"))
{
foreach ($files as $file)
{
if ($file != ".." OR $file != ".")
{
echo $file;

echo "
";
}
}
}


For obvious reasons the second lump of code is more what I want, because I really hate having the true statement do nothing.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...