在分配数组时:"PHP Notice: A non well formed numeric value encountered"

On assigning array: "PHP Notice: A non well formed numeric value encountered"

我收到这个错误:

PHP Notice: A non well formed numeric value encountered in [...]/model.php on line 205

在此 PHP 代码中:

   [...]

   echo 'var_dump($i):' . "\n";
   var_dump($i);

   echo 'var_dump($wawiData[$i][\'date\']):' . "\n";
   var_dump($wawiData[$i]['date']);

   $accRecords[] = array(
    'date' => $wawiData[$i]['date'],  # this is line 205
    'description' => $wawiData[$i]['inv-recipient'],
    'field1' => $wawiData[$i]['inv-no'],
    'account' => $account,
    'contra-account' => $wawiData[$i]['client-no'],
    'amount' => $wawiData[$i]['amount'] * -1,  # this is line 210
    'country-code' => $country,
    'rec-type' => $wawiData[$i]['rec-type'],
    'company' => $wawiData[$i]['company'],
    'name' => $wawiData[$i]['name'],
    'freeze' => 0,
    'inv-link' => 'BEDI "' . $guids[$wawiData[$i]['inv-no']] . '"'
   );
  }
 }
 return $accRecords;
}  # end of method

控制台输出:

var_dump($i):
int(0)
var_dump($wawiData[$i]['date']):
string(10) "08.01.2018"
PHP Notice:  A non well formed numeric value encountered in [...]/model.php on line 205

我找到了很多关于此 PHP 通知 的帖子,但都是关于使用 date() 和其他参数格式错误的函数的代码。

但是,我看不出这与我有什么关系,只是将完美的 string 分配给 array 使用完美的 int 作为索引。

任何人都可以向我解释导致 PHP 通知 的原因吗? (第205行在上面的代码中标出)

谢谢!

P.S.

var_dump($wawiData[$i]):
array(10) {
  ["inv-no"]=>
  string(11) "RE2018-6677"
  ["date"]=>
  string(10) "08.01.2018"
  ["amount"]=>
  string(5) "93,79"
  ["client-no"]=>
  string(5) "12881"
  ["inv-recipient"]=>
  string(27) "(...)"
  ["company"]=>
  string(27) "(...)"
  ["name"]=>
  string(13) "(...)"
  ["rec-type"]=>
  int(2)
  ["country"]=>
  string(11) "Deutschland"
  ["country-code"]=>
  string(2) "DE"
}

Comment by MacBooc:
$wawiData[$i]['amount'] * -1 with 93,79 couldn't be the issue? try to replace your , by ., i'm pretty sure your error will leave

感谢@MacBooc 的回答!

详细说明:

触发PHP通知是因为我试图将值93,79乘以-1。这会引起注意,因为 PHP 期望 .(句点)作为小数点分隔符,因此不喜欢 ,(逗号 - a.k.a。德语小数点分隔符)。

额外的混乱是由于 PHP 声称通知是在第 205 行引起的,尽管实际上是在第 210 行引起的。

我在第 204 行之前添加了以下行:

# remove possible thousands separators
$amount = str_replace('.', '', $wawiData[$i]['amount']);
# change decimal separator from ',' to '.' and mulitply by -1
$amount = str_replace(',', '.', $amount) * -1;
# change decimal separator back from '.' to ','
$amount = str_replace('.', ',', $amount);

第 210 行的新代码:

'amount' => $amount,