gpt4 book ai didi

php - 如何修复 "Recoverable fatal error: Object of class Closure could not be converted to string in..."

转载 作者:可可西里 更新时间:2023-11-01 00:39:00 27 4
gpt4 key购买 nike

当我执行这段代码时出现这个错误。我不知道该怎么办。请帮忙

<?php

$Q = strtoupper($_GET['q']);
$q = ucwords($_GET['q']);
$result = mysqli_query($conn, "SELECT src FROM mytable WHERE '%$Q%' NOT LIKE 0 OR SRC LIKE '%$Q%'");

$total = mysqli_num_rows($result);
$numRows = function()
{
if($total <= 4){
return 1;
} else {
return ($total / 4);
}
};
if($row = mysqli_fetch_array($result)){
?>
<h2>Resultados para la búsqueda <?php echo "$q"?></h2>
<h3>Número de resultados total: <?php echo "$total"?></h3>
<?php
}

最佳答案

你的问题出在这里

$numRows = (function() use ($total) {
if($total <= 4){
return 1;
}else{
return ($total / 4);
}
})();

你必须在括号之间包装函数,如果你想传递参数,你应该使用 use()

关于php - 如何修复 "Recoverable fatal error: Object of class Closure could not be converted to string in...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55783115/

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