[nflug] PHP question
John Nichel
john at kegworks.com
Fri Jun 1 12:58:51 EDT 2007
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
More information about the nflug
mailing list