从数组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.

这是php日志中 $ form_data code>变量/数组的print_r。 p>

  [28-Sep-2018 18:04:03 UTC] Array 
(
 [cfdb7_status] => unread 
 [meno] => data 
 [ 电子邮件] => data 
 [telefon] => phone 
 [meno-ucastnika__1] => data 
 [email-ucastnika__1] => data 
 [meno-komory__1] => 
 [  registracne-cislo__1] => 
 [_wpcf7_groups_count] =>数组
(
 [电子邮件] => 1 
)
 
 [obchodne-meno] => obchod 
 [obchodne-sidlo  ] => fs 
 [ico] => 50426508 
 [dic] => dic 
 [icdph] => icdicko 
)
  code>  pre> 
 
 如何获取 _wpcf7_groups_count key  code>的值? p> 
 
 

如果我想要电子邮件,我只需编写 $ form_data ['email'] code >。 除了 _wpcf7_groups_count code>之外,一切都是这样的。 p>

  $ form_data [ '_ wpcf7_groups_count'] 
上$ form_data [ '_ wpcf7_groups_count'] [0] [ '电子邮件'] 
上$ form_data [ '_ wpcf7_groups_count'] ['电子邮件 '] 
  code>  pre> 
 
 

上面的任何内容都不起作用。 第一个是给我一个非法补偿。 p> div>

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)",