简体   繁体   中英

error: Array to string conversion in

I'm trying to use this code to extract some values:

main

// refhls : array 
foreach($refhls as $refhl){
    $abc = $this->getArrayIntervenants($refhl);
}

function

public function getArrayIntervenants($refhl){
    $requete = $this->bdd->bd->prepare('SELECT intervenant FROM detailsfiche WHERE ref_hl = :ref_hl');
    $requete->bindValue(':ref_hl', $refhl, PDO::PARAM_INT);
    $requete->execute(); // -----MARKED LINE-----
    return $requete->fetchAll(PDO::FETCH_ASSOC);
}

Doing that I get this error message on the marked line:

Notice: Array to string conversion in file.php on line 138

How do I fix that please ?

$refhl is an array. You cannot use array as string.

Try to check the string inside array by

isset($refh1[$positionKey]) { }

if the value exist, and then use it!

Since your variable $refhl is an array, you cannot directly bind it in. Calling a var_dump in the beginning of your function will help you.

var_dump($refhl);

You can then replace your line with something like this:

$requete->bindValue(':ref_hl', $refhl['myArrayKey'], PDO::PARAM_INT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM