【问题标题】:Custom fields in array not posting when containing numbers数组中的自定义字段在包含数字时不发布
【发布时间】:2019-08-27 03:54:23
【问题描述】:

我有一个 PHP 表单,我需要在其中搜索自定义字段。如果自定义字段包含数字,则不会显示为已发布,但会显示一串字母。

如果我var_dump($_POST['customfield']) 它会显示字段、键和值。我尝试了一个foreach 循环来计算有多少字段发布。如果我只发布数字,它会返回 0

$postCustomFields = $_POST['customfield'];

foreach ($postCustomFields as $key => $cfield) {
        if ($postCustomFields[$key][$cfield] != null) {
            $customfields++;
        }
    }

字段被命名为customfield[0]。括号内是字段 ID。我只需要一种让数值可用并计入customfields 数组的方法。

var_dump($_POST['customfield']) 输出。关键是字段ID:

array(9) {
  [3]=>
  string(1) "5"
}

谢谢

【问题讨论】:

    标签: php arrays post


    【解决方案1】:

    您对数组引用感到困惑。您有array [key => value] 的数组,但您尝试访问array[key][value] 之类的数据并且不存在。

    在您的情况下,您的 $postCustomFields[$key] 将包含您的 ID 5

    【讨论】:

    • 噢!谢谢!我将其更改为 $postCustomFields[$key] 并且可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多