[nflug] PHP question

Rob Dege livemotion at gmail.com
Fri Jun 1 13:45:09 EDT 2007


Thank you for the insight.  I changed the loop condition so that it
used foreach instead of while, and the error message went away.

-Rob

On 6/1/07, John Nichel <john at kegworks.com> wrote:
> Rob Dege wrote:
> > A question for the PHP gurus out there.  I am using this function on a
> > webpage:
> >
> > function list_admins($admin_array) {
> >  $i = 0;
> >  while ($admin_array[$i][0])
> >    {
> >      echo "\n    <option value={$admin_array[$i][0]}>
> > {$admin_array[$i][1]} \n";
> >      $i++;
> >    }
> > }
> >
> >
> > The function works correctly, and the info is echo'd to the webpage.
> > However, I get an error message in the apache logs, which I am unable
> > to decipher:
> >
> > [error] PHP Notice:  Undefined offset:  6 in system_functions.php on
> > line 117
> >
> > The line it errors on is the 'while ($admin_array[$i][0])' statement.
> > Does anyone know what it's complaining about?
> >
>
> $admin_array[6][0] is not set.
>
> Do a print_r on your array, and you can see the values.
>
> It's not an error, and you can ignore it, but it's sloppy.  I'm more of
> a foreach guy myself....
>
> foreach ( $admin_array as $admin ) {
>         if ( isset ( $admin[0] ) && isset ( $admin[1] ) ) {
>                 //  both the variables you need are set, so you can
>                 //  safely work with them
>                 ...some code...
>         }
> }
>
> If you don't want empty values being output to the screen, you can also
> add !empty($var_name) to the isset line.
>
> --
> John C. Nichel IV
> System Administrator (ÜberGeek)
> KegWorks
> http://www.kegworks.com
> 716.362.9212 x16
> john at kegworks.com
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>


-- 
-Rob

Ben Franklin Quote: "They that can give up essential liberty to obtain
a little temporary safety deserve neither liberty nor safety."


More information about the nflug mailing list