Re: I am puzzled. Error on one site, no error on the other
| From: | David Harkness | Date: | Sat, 26 Oct 2013 15:39:34 +0000 |
| Subject: | Re: I am puzzled. Error on one site, no error on the other | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-322386@lists.php.net to get a copy of this message | ||
On Fri, Oct 25, 2013 at 5:27 PM, Stephen <stephen-d@rogers.com> 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