RE: [PHP] Array to string conversion error help needed

From: Date: Tue, 08 Mar 2016 19:07:54 +0000
Subject: RE: [PHP] Array to string conversion error help needed
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-325448@lists.php.net to get a copy of this message
Hi! > $sth = $pdo->prepare("SELECT * FROM table1 where id IN ($mylist)" > > > I get error : Array to string conversion... That's because you're interpolating an array within a string, and so thearray is bing coerced to a string (giving a meaningless value). Implode the list into a string and use that instead. For example: $sth = $pdo->prepare("SELECT * FROM table1 where id IN (" . implode(',', $mylist) . ")"; -Tom

« previous php.general (#325448) next »