gpt4 book ai didi

php - 为什么函数接受一个int,但传递一个变量却什么都不做?

转载 作者:行者123 更新时间:2023-11-28 23:14:39 25 4
gpt4 key购买 nike

  $array = $product->get_trims2($year);
for($i = 0; $i < sizeof($array); ++$i) {
var_dump((int)$array[$i]["car_trim"]);
$item = $product->get_trim_by_id((int)$array[$i]["car_trim"]); //line of code in question
var_dump($item);
}

将输出:

整数(29)
阵列(0){
}

  $array = $product->get_trims2($year);
for($i = 0; $i < sizeof($array); ++$i) {
var_dump((int)$array[$i]["car_trim"]);
$item = $product->get_trim_by_id(29); //line of code in question
var_dump($item);
}

将输出:

整数(29)
阵列(1){
[0]=>
阵列(10){
[“身份证”]=>
字符串(2)“29”
[0]=>
字符串(2)“29”
[“年”]=>
字符串(4) "2016"
[1]=>
字符串(4) "2016"
[“制作”]=>
字符串(3)“宝马”
[2]=>
字符串(3)“宝马”
[“模型”]=>
字符串(1)“3”
[3]=>
字符串(1)“3”
[“修剪”]=>
string(22)“带 OEM HID 头灯”
[4]=>
string(22)“带 OEM HID 头灯”
}
}

使用函数:

public function get_trim_by_id($id)
{
$query = $this->pdo->prepare("SELECT * FROM `custom_trims` WHERE `id` = ?");
$query->bindValue(1, $id);
$query->execute();
return $query->fetchAll();
}

最佳答案

使用 bindParam(1, $id) 代替 bindValue(1, $id) 来传递变量值。看起来像是执行时间和绑定(bind)值赋值的问题。

您可以在这里阅读更多内容:

http://php.net/manual/es/pdostatement.bindvalue.php

关于php - 为什么函数接受一个int,但传递一个变量却什么都不做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44417614/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com