【问题标题】:Different result in array depending on the server?根据服务器的不同导致阵列不同?
【发布时间】:2020-05-09 22:53:00
【问题描述】:

编辑: 我在 github 中添加了一个存储库。在“欢迎”中打印结果。 https://github.com/Danven/borrar

LARAVEL 5.8

使用 VAR_DUMP(不同!!!!)

{{ var_dump( $person->cars()->pluck('cars.id') )  }}

本地机器(PHP 7.3.7):

object(Illuminate\Support\Collection)#1215 (1) {
  ["items":protected]=>
  array(4) {
    [0]=> int(1)
    [1]=> int(2)
    [2]=> int(3)
    [3]=> int(4)
  }
}

生产服务器(PHP 7.2.12):

object(Illuminate\Support\Collection)#1215 (1) {
  ["items":protected]=>
  array(4) {
    [0]=> string(1) "1"
    [1]=> string(1) "2"
    [2]=> string(1) "3"
    [3]=> string(1) "4"
  }
}

【问题讨论】:

标签: php arrays laravel


【解决方案1】:

因为在 PHP 7.3 中包含有效十进制整数的字符串,除非该数字前面有 + 符号,否则将被强制转换为整数类型。例如。密钥 8 实际上将存储在 8 之下。另一方面,08 不会被强制转换,因为它不是有效的十进制整数。

您可以阅读:https://www.php.net/manual/en/language.types.array.php

【讨论】:

  • 我已经在另一台服务器上使用 PHP 7.1.33 和 PHP 版本 7.2.26 进行了测试,生产状态为:[1,2,3,4]。这些值被解释为整数
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 1970-01-01
  • 1970-01-01
  • 2020-12-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多