0

我正在尝试添加一个问题,并且该问题有 4 个选项。在这些选项中,当然只有一个是正确的。但是,提交表单后,我收到如下数据:

Array
(
    [option_A] => answera
    [option_B] => answerb
    [option_C] => answersc
    [option_D] => answerd
)

我想用一个键重新分配这些数组,如下所示:

Array
(
    [answers] => Array
        (
            [0] => answerd
            [1] => answerb
            [2] => answerc
            [3] => answerd
        )

)

是否有可能得到我期望的结果?这个功能可以实现array_walk()吗?

4

1 回答 1

1

您可以如下使用。通过创建新数组。

<?php

$Output = array();

$input = array("option_A" => "answera", "option_B" => "answerb", "option_C" => "answersc"
    , "option_D" => "answerd");

foreach ($input as $key => $value) 
{   $PArray[] = $value; }

$Output["answers"] = $PArray; 

echo "<pre>";print_r($Output);exit();

?>
于 2019-03-14T07:51:44.357 回答