【问题标题】:Error Retrieving Array Value检索数组值时出错
【发布时间】:2017-11-15 23:48:26
【问题描述】:

我有一个包含以下值的数组,

Array(
[new_count] => 1
[updated_count] => 0
[error_count] => 0
[error_indices] => Array
    (
    )

[unmodified_indices] => Array
    (
    )

[persisted_recipients] => Array
    (
        [0] => ZEBhcy5jb20=
    )

[errors] => Array
    (
    )

)

我试图只将这个值传递给一个变量,

[persisted_recipients] => Array
    (
        [0] => ZEBhcy5jb20=
    )

$recipient_id = $array_retorno['persisted_recipients'][0];

但我收到以下错误

未定义的偏移量:0 [APP\Controller\PostsController.php,第 129 行]

怎么了?

【问题讨论】:

  • 那么$array_retorno是一个包含多个数组的数组?听起来你需要$array_retorno[5][0]
  • 您能var_dump($array_retorno) 并在问题中发布结果吗?我不确定数组中的实际内容。
  • 从 var_dump 数组返回 (7) { ["new_count"]=> int(1) ["updated_count"]=> int(0) ["error_count"]=> int(0) [ "error_indices"]=> 数组(0) { } ["unmodified_indices"]=> 数组(0) { } ["persisted_recipients"]=> 数组(1) { [0]=> 字符串(20) "ZHNkc0Bkc2RzZC5jb20=" } [“错误”]=> 数组(0){ } }
  • 您在此处显示的数据和代码不会导致该错误。请使用可重现您的问题的工作代码 sn-p 更新您的帖子!

标签: php cakephp cakephp-2.0


【解决方案1】:

尝试使用 get_file_contents() 函数来获取输出数据。或尝试
json_decode(json_encode($array), true)。

【讨论】:

  • 老兄,他给我们看的数组,只是php代码的输出,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多