It's strange that when I run the code below in a function, it executes it, but when I run it inside a while loop it gives me this notice:
Notice: Uninitialized string offset: 4
function thing($content) {
preg_match_all("/(<h[^>]*>.*?<\/h2>\n*<p>.*?<\/p>)/", $content, $array);
$i = 1;
$limit = count($array[0]);
$array = $array[0][4];
echo $array; //outside loop
while ( $i <= $limit) {
$array = $array[0][4];
echo $array; inside loop
$i++;
}
return $content;
}
add_action('the_content', 'thing', 50);
Why is this happening?
I want to access the array keys one at a time so doing this $array = $array[0][4];
is required