Foreach problems


#1

Hi,
Can anyone see what the problem may be with this bit of code.
I am getting this error Warning: Invalid argument supplied for foreach() in /home/dezinert/public_html/tester.php on line 53

Here is the snippet <?php session_start(); foreach ($_SESSION['_amember_subscriptions'] as $sub); ///This is line 53 if ($sub['payment_id']){ $diff = (strtotime($s['expire_date']) - time()) / (3600*24); if ($diff > 0){ print "Your subscription expires in $diff days"; } } ?>

Thanks in advance


#2

are you using a multi-dimensional array?

Typically you pass an array, in this case the session array, and the foreach loops through the array and does something with each element.

You appear to be passing a single element of the array, _amember_subscriptions, which would cause the error.


#3

Thanks,

I am fairly new to php and finding it very interesting.
I asked the following question elsewhere and this was the result.
I ran this code, and the outcome was false. :cry:


#4

So it is not an array (thus the Bool FALSE).

You must supply an array to the foreach function.

Should your foreach line be like this?

[php]
foreach ($_SESSION as $sub);
[/php]