plznty Posted December 21, 2009 Share Posted December 21, 2009 how can i make an array list based on another array list for example array of ("domain.com","domain2.com","domain3.com"); for each of the above if the file_get_contents = "working" then make a new array list of the ones that have the file contents of "working" thanks. Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/ Share on other sites More sharing options...
Adam Posted December 21, 2009 Share Posted December 21, 2009 Loop through them.. $working = array(); foreach ($domains as $domain) { if (....) { $working[] = $domain; } } Not exactly sure what you're trying to do with file_get_contents = "working", so left that part out. Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981636 Share on other sites More sharing options...
JAY6390 Posted December 21, 2009 Share Posted December 21, 2009 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981645 Share on other sites More sharing options...
akitchin Posted December 21, 2009 Share Posted December 21, 2009 also have a look at array_map. Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981647 Share on other sites More sharing options...
plznty Posted December 21, 2009 Author Share Posted December 21, 2009 Thank you for also the code help. Thanks for all recommendations and contributions. Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981785 Share on other sites More sharing options...
salathe Posted December 21, 2009 Share Posted December 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/185895-arrays-on-conditions/#findComment-981854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.