Strange behaviour of foreach in PHP 4.3.11

Discussion in 'Programming/Scripts' started by minimi, May 26, 2005.

  1. minimi

    minimi New Member

    I found a strange behaviour of foreach in PHP 4.3.11. For example, if you have the following code:

    PHP:
    <?
    $elements[0] = 'bla';
    $elements[1] = 'blubb';

    foreach(
    $elements as $element){
      
    print_r($element);
    }
    ?>
    it prints

    Code:
    Array
            (
                [0] => bla
                [1] => 0
            )
    Array
            (
                [0] => blubb
                [1] => 1
            )
    instead of the strings bla and blubb... Is this a bug in PHP 4.3.11?
     
  2. flo

    flo New Member

  3. minimi

    minimi New Member

    Is this bug fixed in PHP 5? Or do I have to use PHP 4.3.9?
     
  4. falko

    falko Super Moderator Howtoforge Staff

    As far as I know PHP 5 seems to behave the "normal" way...
     

Share This Page