$i = 0; $j = 0; while (isset($matches[0][$i]) && isset($matches[1][$j])) { $url($i) = $matches[0][$i]; $anchortext($j) = $matches[1][$j]; $towrite .= "\$url = $url\n"; $towrite .= "\$anchortext = $anchortext\n"; $i++; $j++; }