Jump to content

arrays on conditions


plznty

Recommended Posts

Something like this should do it

$domains = array('http://www.google.com','http://www.jaygilford.com','http://www.some-random-domain.com');
$active_domains = array();
foreach($domains as $v) {
    if($fp = fopen($v, 'r')) {
        fclose($fp);
        $active_domains[] = $v;
    }
}

echo '<pre>'.print_r($active_domains, true).'</pre>';

Link to comment
https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981645
Share on other sites

also have a look at array_map.

 

array_filter would be more appropriate in this instance, since the OP is looking to filter the array based on some condition (the associated file having certain contents). That said, it doesn't make sense to process these serially but perhaps the OP just needs something simple so lets not delve into that. :shy:

Link to comment
https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981854
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.