PHP Warning: Invalid argument supplied for foreach() error
<p>I haven't been able to find a solution in the suggested questions that would help me solve this issue. </p>

<p>I have the following code, which does work, but it throws a PHP Warning:  Invalid argument supplied for foreach() error. </p>

<p>In my code, I am adding any authors from $author2 to the $authdisplay array that have the same role as the primary author ($auth_role[0]). </p>

<p>I have checked to make sure that the $author2, $auth2_role, $auth_role, and $authdisplay are all arrays, and $author2 and $auth2_role have the same number of elements. ($author is a string.)</p>

<p>Any tips and help figuring this out would be appreciated. </p>

<pre><code>   $author = $this-&gt;getPrimaryAuthor();
   $author2 = $this-&gt;getAuthor2Names();
   $auth_role = $this-&gt;getPrimaryAuthorsRoles();
   $auth2_role = $this-&gt;getAuthor2Roles();
   $authdisplay[] = $author;

  foreach($author2 as $key=&gt;$field) {
       if ($auth2_role[$key] == $auth_role[0]) {
          $authdisplay[] = $field;
       }
   }
   return $authdisplay;
 }
</code></pre>