sort array by found first?

Discussion in 'PHP' started by Brinked, Aug 21, 2008.

  1. #1
    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
     
    Brinked, Aug 21, 2008 IP
  2. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    William[ws], Aug 21, 2008 IP