gpt4 book ai didi

javascript - 如何在 PHP 中调试 "A non-numeric value encountered"?

转载 作者:行者123 更新时间:2023-11-30 14:18:49 25 4
gpt4 key购买 nike

我在 BookinginfoController.php 第 101 行收到此 PHP 返回错误:

A non-numeric value encountered...

这是脚本的一部分。请在这里用基本术语解释。

$token =csrf_token();
$idmy = Auth::user()->id;

$bookingget = DB::table('booking')

->where('user_id', '=', $idmy)
->where('status', '=', 'pending')
->where('token', '=', $token)
->orderBy('book_id','desc')
->get();

$neshopp = $bookingget[0]->shop_id;

$shopnewie = DB::table('shop')
->where('id', '=', $neshopp)
->get();

$id = $shopnewie[0]->user_id;



$userdetails = DB::table('users')
->where('id', '=', $id)
->get();

$booking = DB::table('booking')
->where('token', '=', $token)
->where('status', '=', 'pending')
->where('user_id', '=', $idmy)
->orderBy('book_id','desc')
->get();


$ser_id=$booking[0]->services_id;
$sel=explode("," , $ser_id);
$lev=count($sel);
$ser_name="";
$sum="";
$price="";

for($i=0;$i<$lev;$i++)
{
$id=$sel[$i];



$fet1 = DB::table('subservices')
->where('subid', '=', $id)
->get();
$ser_name.=$fet1[0]->subname.'<br>';
$ser_name.=",";



$fet2 = DB::table('seller_services')
->where('subservice_id', '=', $id)
->where('shop_id', '=', $neshopp)
->get();
$price.=$fet2[0]->price.'<br>';
$price.=",";




$ser_name=trim($ser_name,",");
$price=trim($price,",");
$sum+=$fet2[0]->price;

我正在使用 PHP 7.2

第99、100、101行是

$ser_name=trim($ser_name,",");

$price=trim($price,",");

$sum+=$fet2[0]->price;

最佳答案

如果您使用的是 php 7.1+,这是因为您将 $sum 变量初始化为空字符串:

$sum = '';

相反,您应该将其初始化为数字:

$sum = 0;

参见 an example .

显然,$fet2[0]->price 需要是数字,但如果它是字符串,php 会在没有警告的情况下转换它。

关于javascript - 如何在 PHP 中调试 "A non-numeric value encountered"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082760/

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