Friday, 11 May 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

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...