【问题标题】:Error Notice Array to string conversion after updating CF7更新 CF7 后错误通知数组到字符串的转换
【发布时间】:2020-11-20 21:51:51
【问题描述】:

我需要帮助解决以下错误

Notice: Array to string conversion in /www/test_123/public/wp-content/plugins/test-functions/match-functions.php on line 302

下面是写在 301 和 302 行的,不知道哪里错了。当我将联系表 7 更新到最新版本时会发生这种情况,但在 5.1.6 上没有这样的错误。

$location = WC_Geolocation::geolocate_ip();
$p1_dob = $your_birth_year . "-" . $your_birth_month . "-" . $your_birth_day;
$p2_dob = $partners_birth_year . "-" . $partners_birth_month . "-" . $partners_birth_day;
$pmf_love_match_html_url = "https://primary.astrowebserver.net/v2/reports/CreateShortHTML/REL-NEW-DUALMATCH/?APIKEY=012bc72f-093a-4617-9432-0cbb55662ad7&P1FirstName=" . $your_first_name . "&P1DOB=" . $p1_dob . "&P1Sex=" . $your_gender . "&P1Country=" . $location['country'] . "&P2FirstName=" . $partners_first_name . "&P2DOB=" . $p2_dob . "&P2Sex=" . $partners_gender . "&P2Country=" . $location['country'];

【问题讨论】:

  • 严格来说这不是一个错误,而是一个通知。使用 implode() 函数将数组正确转换为字符串或以其他方式识别数组元素。
  • 如果这些字段 $your_birth_year 等来自联系表格 7。您如何获取这些字段的值,它们中的任何一个是选择(下拉)还是复选框?

标签: php wordpress contact-form-7


【解决方案1】:

您将不同的变量附加到 string 中。其中一些变量不是string 类型(而是array),因此不能附加到字符串。

$string_val = "foo";
$result = "-" . $string_val . "-" // works fine

$array_val = [
    "foo" => "bar",
    "bar" => "foo",
];
$result = "-" . $array_val . "-" // 'Notice: Array to string conversion ...'

【讨论】:

  • 您好,谢谢您的回复,但我不是很专业,所以您能告诉我在我的第一条消息中发送的代码中要更改哪些内容。谢谢
  • 打印所有你正在使用的变量,看看哪些不是字符串。然后,将它们更改为正确的值。
猜你喜欢
  • 2017-01-31
  • 1970-01-01
  • 2015-02-26
  • 2012-07-15
  • 2017-12-02
  • 1970-01-01
  • 2013-11-30
  • 1970-01-01
  • 2013-06-23
相关资源
最近更新 更多