Re: Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Oct 24, 2009 at 7:59 AM, Ashley Sheridan
<ash@xxxxxxxxxxxxxxxxxxxx>wrote:

> On Sat, 2009-10-24 at 06:57 -0400, Ron Piggott wrote:
>
> > The following line gives me an error message when there aren't any
> > values in the array --- how do I accommodate this?
> >
> > Warning: Invalid argument supplied for foreach()
> >
> > foreach ($_SESSION['order'] AS $key => $value ) {
> >
> >
>
>
> Do an isset() on $_SESSION['order'] first to determine if the variable
> even exists, then do is_array() to determine if it's an array or not
> before trying to iterate it. My guess is that $_SESSION['order'] isn't
> an array all the time.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>
foreach works with array and instances.
Unless the class implements Transversable, it's public properties are used
on the loop.


foreach($object as $prop => $value )
//php translates the foreach into something like this...
foreach(get_object_vars($object) as $prop => $value )

-- 
Martin Scotta

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux