I have an array constructed out of several strings (HTTP addresses) on which I run a PHP Filter and the unset() method to remove non-valid URLs. However, the last array item is never removed - and I don't know why, or how I solve this. I'm hoping you guys can help.
$url1 = "http://localhost/work/project/scrapes/1.html";
$url2 = "";
$url3 = "";
$urls = array($url1, $url2, $url3);
for($x = 0; $x < sizeof($urls); $x++){
if(!filter_var($urls[$x], FILTER_VALIDATE_URL)){
unset($urls[$x]);
}
}
print_r() gives me this:
Array ( [0] => http://localhost/work/project/scrapes/1.html [2] => )
I have no idea why $urls[2] is still there, and why it's not removed.