0

Does the following code work in php4

foreach ($array as $i => $values) {
    print "$i {\n";
    foreach ($values as $key => $value) {
        print "    $key => $value\n";
    }
    print "}\n";
}

This works with php5 but the same loop with no changes does not work with the version 4. The foreach iterates through the loop but the values are not displayed. Could someone help me with this

4
  • How the $array is structured? Commented Dec 19, 2011 at 9:16
  • Wy do you even bother about PHP4? It's outdated and not supported version of PHP. Every shared hosting provides PHP5 (it's 8-yrs old!). Commented Dec 19, 2011 at 9:17
  • just tried on an old 4.4 php installation: it works fine. Commented Dec 19, 2011 at 9:18
  • For me, the reason is a big ball of muddy php4 code I have to maintain since 2001 Commented Dec 19, 2011 at 9:29

2 Answers 2

1

Should work fine in PHP 4 there is nothing PHP 5 specific there.

It is more likely your array is different in between the 2 versions. As we can't see the entire code its difficult to tell.

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

Comments

0

Should work in php4 as well:

foreach ($array as $i => $values) {
    echo $i."{\n";
    foreach ($values as $key => $value) {
        echo $key ."=>". $value."\n";
    }
    echo "}\n";
}

Comments

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.