我尝试使用 intval 将我的字符串数组转换为 INT 但是结果/返回总是int(1) 而数据库值为 14698我的数据库:+-------+---------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+---------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || curr | char(3) | NO | | NULL | || rate | int(11) | NO | | 0 | |+-------+---------+------+-----+---------+----------------++----+------+-------+| id | curr | rate |+----+------+-------+| 1 | USD | 1 || 2 | IDR | 14698 || 3 | JPY | 112 || 4 | EUR | 1 || 5 | THB | 33 |+----+------+-------+这是我的 crudQuery.php 页面: <?phprequire 'config.php';if (isset($_POST['save'])) { require_once 'functions.php'; $qty = $_POST['qty']; $qty = (int) $qty; $curr = $_POST['curr']; $price = $_POST['price']; $price = (int) $price; $rate = queryInt("SELECT rate FROM rate_master WHERE curr = '$curr'"); var_dump($rate);echo $rate[0];这是我的functions.php页面:<?phprequire 'config.php'; function queryInt($query) { global $conn; $result = mysqli_query($conn, $query); $rows = []; while ($row = mysqli_fetch_assoc($result)) { $rows [] = intval($row); } return $rows; }然后, var_dump 的结果是:array(1) { [0]=> int(1) } 1我应该做什么,以便从数据库中返回值而不是 1 ?
1 回答
月关宝盒
TA贡献1772条经验 获得超5个赞
while ($row = mysqli_fetch_assoc($result)) {
$rows [] = intval($row);
}
mysqli_fetch_assoc返回一个数组,您不能将一个数组“转换为 int”,并期望它有一个有意义的结果。
intval($row)需要是intval($row['rate'])
- 1 回答
- 0 关注
- 111 浏览
添加回答
举报
0/150
提交
取消