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
https://forums.phpfreaks.com/topic/38901-foreach-help/
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
https://forums.phpfreaks.com/topic/38901-foreach-help/#findComment-187076
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
https://forums.phpfreaks.com/topic/38901-foreach-help/#findComment-187082
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.