Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is it ok to loop array again in nested loop and also change the array?

I've an URL's array with entries(as array key) of either an URL or domain:example.com

In case of this entry : domain:example.com I want to remove all URLS containing example.com as domain:

foreach (array_keys($urls1) as $line) {
        if (preg_match('/domain:(.*)/i', $line, $matches)) {
            $domain = $matches[1];
            foreach (array_keys($urls1) as $line2) {
                if ($url_domains[$line2] == $domain) {
                    unset($urls1[$line2]);
                }
            }
        }
    }
share|improve this question
    
It's certainly ok to loop over it. But I'm not sure wheter it's ok to modify it and how. –  Pavel Šimerda 15 mins ago
    
It might be better to do an array_walk or array_map. If it works fine with this code, I don't see any reason to change it. –  Dave Chen 7 mins ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.