【问题标题】:error when get value from array preg_replace(): Parameter mismatch, pattern is a string while replacement is an array"从数组 preg_replace() 获取值时出错:参数不匹配,模式是字符串,而替换是数组”
【发布时间】:2019-05-18 06:54:33
【问题描述】:

当我获得第二个数组值并将其传递给变量时遇到了一些问题。

array:0 [
    "student_id" => 1212
    "class" => array:1 [
     "id" => 550
      ]
    ]

通常$student= array_get($data, 'student_id'); 能够获得价值。

现在我正在尝试获取类似于 $class= array_get($data, 'class', 'id'); 的类 ID 但它弹出这个错误;

【问题讨论】:

  • 什么错误?什么preg_replace
  • @user3783243 array_get() 是一个 laravel 辅助函数。我想它在引擎盖下使用 preg_replace。

标签: php laravel laravel-4


【解决方案1】:

要从嵌套数组中获取值,请使用 dot 表示法。

$class = array_get($data, 'class.id');

【讨论】:

    猜你喜欢
    • 2017-03-26
    • 2015-06-19
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    相关资源
    最近更新 更多