Changing a value of a variable inside foreach loop PHP
I have a problem. I should change the value of a variable inside a foreach
loop in php, but the value holds predefined value all the time. Here is
the code:
$returnValue = "";
foreach($vinArray as $vinValue){
$sql_vin_check = "SELECT * FROM users WHERE vin LIKE '%:vin%'";
$stmtvincheck = $pdo->prepare($sql_vin_check);
$stmtvincheck->bindParam(':vin', $vinValue);
$stmtvincheck->execute();
$vinCheck = $stmtvincheck->rowCount();
$stmtvincheck->closeCursor();
echo $vinValue;
if($vinCheck != 0){
$returnValue = $vinValue; break;
}
}
return $returnValue;
And $returnValue holds the "" value. I tried echoing $vinValue variable
and it's not empty when the loop breaks.
What am I doing wrong?
No comments:
Post a Comment