Jump to content

Foreach help


crazyfrog

Recommended Posts

Hi,

 

Can anyone see a problem with this bit of code?

    <?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";
 print ("$sub");
  }
}
?>

 

I am getting the following error and cant understand why. reading through other topics, i seem to think it is something to do with arrays?

Warning: Invalid argument supplied for foreach() in /home/*****/public_html/tester.php on line 53

 

Thanks >:(

Link to comment
Share on other sites

<?php session_start();

$x=$_SESSION['_amember_subscriptions'];

foreach($x as $sub){

if ($sub['payment_id']){

$diff = (strtotime($s['expire_date']) - time()) / (3600*24);

if ($diff > 0){

print "Your subscription expires in $diff days";

 print ("$sub");
  }
   }
     }
?>

Link to comment
Share on other sites

 

foreach ($_SESSION['_amember_subscriptions'] as $sub);  //This is line 53

 

 

Warning: Invalid argument supplied for foreach() in /home/*****/public_html/tester.php on line 53

 

this is caused when $_SESSION['_amember_subscriptions'] is not an array.  You may want to double check this.

 

Also, giving a line like

foreach ($_SESSION['_amember_subscriptions'] as $sub);  // this is meaningless

because you terminated the foreach loop with the semicolon ';' before it can actually do anything:

 

foreach ($_SESSION['_amember_subscriptions'] as $sub)

{

  // your code here

 

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.