I have an array loop such as the following: $tagnames = array("h1", "strong", "h2", "h3"); foreach ($tagnames as $tagname) { $pattern = "/<$tagname>(.*?)<\/$tagname>/"; preg_match_all($pattern, $content, $matches); foreach ($matches[1] as $match) { $match = rtrim($match); $jump = "<a href=\"#$match\"><b>" . $match . "</b></a> | "; print str_replace(array(":","<br />"), "",$jump); } } PHP: however it prints the $jump links in order of h1, strong, h2 and then h3. I would like to print them as they are found in the content for example: <h1>This is the heading</h1> <strong>This is some line in bold</strong> <h1>This is another heading</h1> Code (markup): So I would like it to print out in the order found first to last so it would be the H1, strong then the H1 again. Any suggestions? Thanks in advance
Well the way u have it , i dunno if it would work becuz seeing how u have your array setup the foreach is reading it in the order u have it in , maybe someone better on arrays can find a way to... but from my understanding the foreach is only going to find it in the order u have it in