0

How can I set $sections up so it works outside of the while loop?

while($sections = mysql_fetch_array($query)) {
        $section_name = $sections['location'];
        $sections[$section_name] = $sections['content'];
        echo $sections['main'];
    }

$sections['main'] echoes correctly here, but when I run it further down in the code (outside the while loop) it displays nothing. I assume this is something to do with the scope?

I've tried both $sections = array(); and $sections = ''; prior to the loop. Both don't solve the issue. Thanks.

1 Answer 1

3

Last iteration would null the $sections variable, thus breaking the while loop.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep. Fixed by changing the new array name to something else. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.