Re: I am puzzled. Error on one site, no error on the other

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 25, 2013 at 5:27 PM, Stephen <stephen-d@xxxxxxxxxx> wrote:

> The warning is from this code:
>
> if ( in_array( $keys, $photo_ids ) )
>
> *Warning*: in_array() expects parameter 2 to be array, null given in
> */home/rois3324/include/**cpprocessforms.php* on line *203*
>

This happens when you allow PHP to create the array for you. Before
iterating through another (possibly empty) array and adding photo IDs
to $photo_ids,
you must assign an empty array to the variable. You need to add

    $photo_ids = array();

at the top of the function. PHP will happily assign a new array to $photo_ids
if the variable is null in this loop:

      while ( list( $id ) = $stmt->fetch(PDO::FETCH_NUM)) {
>         $photo_ids[] = $id;
>       }


But if that statement produces an empty result set, $photo_ids will remain
null.

Cheers,
David

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux