I have text and a pattern that runs several times. I want it to return an incremented number every time it finds another match. Any ideas?

Code:
function return_replace() {
		static $i = 0;
		$a = array( '<div><h6 class="toggle" num="' . $i . '">', '</h6>', '<p num="' . $i++ . '">', '</p></div>' );
		return $a;
	}
	
	function format_toggle_content($content) {
		$i = 0;
		
		$pattern = array( '/<pre><strong>/im', '/<\/strong><\/pre>/im', '/<pre>/im', '/<\/pre>/im' );
		
		return preg_replace( $pattern, return_replace(), $content );
	}