I am just practicing some php and decided to attempt to search through my wamp directory as I've never really practiced this at all.
Basically, I am using array_search() to search my directory files array for a value. The documentation states that if it doesn't match the value, it returns boolean false but can also return another type which value equates to false for example int type with a value of 0.
My question is, what is the best way to deal with this? I'm kinda lost. I'm using array_search() because I need the index so I can build the path string up. I realize I could count the array length and loop, saving the value into a variable (if it is found) and then create my own variable and value should it not find the value.
I'm wondering what the best way is to go about getting the values I need, and also how do we deal with these php functions which possibly return different types when it means false.(as in what do we check, boolean false, integer 0, string false) I will use mkdir() if it is false but I just need to know HOW to check the value effectively and minimizing the bugs.
On php.net is states to check it using the identical operator but what if it does by chance return integer 0, it won't deal with the error properly. Maybe I could do a switch() but I think it could possibly be unnecessary?
I've done a little bit of code:
$dir_name = dirname(__FILE__);
echo $dir_name."<br />";
$dir_files = scandir($dir_name);
$index = array_search("GardenableImproved",$dir_files);
$site_dir = scandir($dir_name."\\".$dir_files[$index]);
echo "directory does not exist.";
Not sure if it helps much.
Thank you for any information and help you can put my way.