The problem here lies with the each function, I believe. I played with this for a minute and that's where I ran into problems with unexpected behaviour. Regardless, I was able to get expected functionality using foreach instead of the while loop. While foreach isn't available in PHP3 it is in all versions of PHP4. If you can't use foreach, writing the while loop differently (not using each()) should work better.

HTH,
Jason k Larson


Patrick Teague wrote:
I'm currently having a problem with another array in a class & I can't
figure it out -

class myClass
{
    function myClass($arr = array( 'item1'=>array('a','b','c'),
'item2'=>array('a','b','c') ) )
    {
        print_r( $arr );
        while( list($key,$val) = each($arr) )
        {
            print($key."=".$val);
        }
    }
}

now, if I say

$mine = myClass();

it only prints the print_r statement, but not the print($key."=".$val)
statment meaning it doesn't even bother entering the loop.  However if I say

$mine = myClass(array( 'item1'=>array('a','b','c'),
'item2'=>array('a','b','c') ) );

it prints both...  is there some reason why I need to repeat the default
value when creating the class?  I've also tried using a "" string on class
creation, but no luck there either.

Patrick



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to