Php 是否可以将数组或类保存到$\u POST?

Php 是否可以将数组或类保存到$\u POST?,php,wordpress,post,Php,Wordpress,Post,我有一个元框插件,我在wordpress中工作。我有一个按钮,你可以用它添加输入,可以是文本区域,也可以是文本输入。当用户更新他们的帖子时,文本框中的任何内容和输入都会保存到帖子元中,但是我想循环输入,并为每个帖子添加主观数据 例如,目前我只是将所有输入的值一个接一个地保存到“BBPlugin resources”键,如下所示: 'a:2:{ i:0;s:6:"some words"; i:1;s:14:"some more words"; }' 我想

我有一个元框插件,我在wordpress中工作。我有一个按钮,你可以用它添加输入,可以是文本区域,也可以是文本输入。当用户更新他们的帖子时,文本框中的任何内容和输入都会保存到帖子元中,但是我想循环输入,并为每个帖子添加主观数据

例如,目前我只是将所有输入的值一个接一个地保存到“BBPlugin resources”键,如下所示:

 'a:2:{
        i:0;s:6:"some words";
        i:1;s:14:"some more words";
    }'
我想我所知道的最接近json的东西就是json,在json中会存在以下类型的脚本,但我不知道post meta是否可能。在任何情况下,我都希望能有这样的东西:

 'a:2:{
        "title": "a metabox full of inputs";
        "input boxes"{
            "input 1"{
                "text": "some words",
                "type:"textarea"
            };
            "input 2"{
                "text": "some more words",
                "type:"input"
            };
        };
    }'

这样的事情可能吗?

从此创建数组

我假设您在
$\u POST['input\u type']
中获得输入类型,在
$\u POST['input\u text']
中获得实际输入

$input_data = array(
                    'title'         => "a metabox full of inputs",
                    'input_boxes'   => array(
                        'text'  => $_POST['input_text'],
                        'type'  => $_POST['input_type'],
                        ),
                );

//for getting multiple entries under input_boxes run a foreach loop of all text boxes and text area and get them in single array
// for eg : $inpur_arr and put it in the key 'input_boxes' =>  $inpur_arr
/* else 'input_boxes'   => array(
                        'text'  => $_POST['input_text'],
                        'type'  => $_POST['input_type'],
                        ),*/



//will save the json encoded data
update_post_meta($post_ID, 'input_json', json_encode($input_data));

//wil save the serialized data as shown in your example above
update_post_meta($post_ID, 'input_json', $input_data);

从这个数组创建数组

我假设您在
$\u POST['input\u type']
中获得输入类型,在
$\u POST['input\u text']
中获得实际输入

$input_data = array(
                    'title'         => "a metabox full of inputs",
                    'input_boxes'   => array(
                        'text'  => $_POST['input_text'],
                        'type'  => $_POST['input_type'],
                        ),
                );

//for getting multiple entries under input_boxes run a foreach loop of all text boxes and text area and get them in single array
// for eg : $inpur_arr and put it in the key 'input_boxes' =>  $inpur_arr
/* else 'input_boxes'   => array(
                        'text'  => $_POST['input_text'],
                        'type'  => $_POST['input_type'],
                        ),*/



//will save the json encoded data
update_post_meta($post_ID, 'input_json', json_encode($input_data));

//wil save the serialized data as shown in your example above
update_post_meta($post_ID, 'input_json', $input_data);


$\u将自身发布为数组。是否可以在中保存数组?可以。您可以将一个数组设置为另一个数组。它被称为多维数组存储库,请在答案中输入该值,我将其标记为$\u将其自身发布为数组。是否可以在中保存数组?是的。您可以将一个数组设置为另一个数组。它被称为多维数组,请将其输入到答案中,我会将其标记为off谢谢,我会给它一个shotwill$\u POST['input\u text']返回输入值,输入值的名称(而不是id)?yes$\u POST['input\u text']其中“input_text”是您需要ID的输入字段的名称。。我猜您可能会考虑通过IDN获取输入类型,因为您只从名称获取值。。您可以做一件事,为包含其类型的输入创建一个隐藏字段,并通过隐藏的输入名称获取其类型谢谢,我会给它一个shotwill$\u POST['input\u text']返回输入值,输入名称(而非id)为input\u text?是的$\u POST['input\u text'],其中'input\u text'是您需要id的输入字段的名称。。我猜您可能会考虑通过IDN获取输入类型,因为您只从名称获取值。。您可以做一件事,为包含其类型的输入创建一个隐藏字段,并通过隐藏的输入名称获取其类型