-1

When trying to execute this code am getting an error like this

Invalid argument supplied for foreach() in line number 2

My code is:

<?php
$contacts= $getcontact_access->GetContacts($oauth, $access_token, $access_token_secret, false, true,$emails_count);
foreach($contacts as $k => $a)
 {
  $final = end($contacts[$k]);
   foreach($final as $email)
    {
     echo '<section style=" border-bottom:1px solid #d9d7d7; padding-left:150px">'.'<input class="label" value="'.$email["address"].'"  name="invite[]" type="checkbox" checked>'.$email["address"]."</section>";
    }
 }
?>

Have you any idea?

Shubham Verma
  • 39
  • 1
  • 12

2 Answers2

1

Yes, general idea is to debug. You should check

var_dump($contacts);

and see what's inside.

It's Friday so may be I'm too kind when doing debug for others

Community
  • 1
  • 1
Alma Do
  • 37,009
  • 9
  • 76
  • 105
0

Yes.... I found its solution,

It will be.

<?php
$contacts= $getcontact_access->GetContacts($oauth, $access_token, $access_token_secret, false, true,$emails_count);
if (is_array($contacts))
{
foreach($contacts as $k => $a)
 {
  $final = end($contacts[$k]);
   foreach($final as $email)
    {
      echo '<section style=" border-bottom:1px solid #d9d7d7; padding-left:150px">'.'<input class="label" value="'.$email["address"].'"  name="invite[]" type="checkbox" checked>'.$email["address"]."</section>";
    }
 }
}
?>
Shubham Verma
  • 39
  • 1
  • 12