drxm72811 2018-09-28 18:15
浏览 62
已采纳

从数组PHP中获取值 - 非法偏移量

This is the print_r from the $form_data variable / array in php log.

[28-Sep-2018 18:04:03 UTC] Array
(
    [cfdb7_status] => unread
    [meno] => data
    [email] => data
    [telefon] => phone
    [meno-ucastnika__1] => data
    [email-ucastnika__1] => data
    [meno-komory__1] => 
    [registracne-cislo__1] => 
    [_wpcf7_groups_count] => Array
        (
            [emails] => 1
        )

    [obchodne-meno] => obchod
    [obchodne-sidlo] => fs
    [ico] => 50426508
    [dic] => dic
    [icdph] => icdicko
)

How can I get the value of _wpcf7_groups_count key?

If I want email I simply wrote $form_data['email']. Everything goes like this except _wpcf7_groups_count.

$form_data['_wpcf7_groups_count']
$form_data['_wpcf7_groups_count'][0]['emails']
$form_data['_wpcf7_groups_count']['emails']

Anything from above doesn't work. The first is giving me an illegal offset.

  • 写回答

1条回答 默认 最新

  • douyunhuan9886 2018-09-28 18:19
    关注

    From the data you posted(*),

    $form_data['_wpcf7_groups_count']['emails']
    

    should work, and yield 1.

    Note that the parent key value is an array, so if the form data goes through some sort of templating engine, the problem might lie there.

    I find it strange that you get an error for the first method, and not for the others: in PHP, if you can't reference an array key, you cannot reference any of the descendants, and you still get the error from the parent key. This is what makes me suspect that something else is afoot.

    ==========

    (*) I assumed that you have deleted some information while keeping the formatting. Otherwise writing

    [meno-komory__1] => 
    [registracne-cislo__1] => 
    

    could possibly be interpreted as a nested key. I saw no 'Array', so I assumed there was just some data missing. But next time write it explicitly to avoid any ambiguity:

    [meno-komory__1] => "(redacted)",
    [registracne-cislo__1] => "(array, redacted)",
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c