-2

我认为这是一个艰难的!只有专家?

好的,我有一些变量(从 get_defined_vars 返回):

Array
    (
        [lead] => Array
            (
                [2] => fstory
                [4] => him
                [5] => trtr
                [1] => 508b38ee02f502.23680245.png
            )

        [form] => Array
            (
                [id] => 3

                    )

                [fields] => Array
                    (
                        [0] => Array
                            (
                                [adminLabel] => formname
                                [id] => 2

                            )

                       [1] => Array
                        (
                            [adminLabel] => hisher
                            [id] => 4

                        [2] => Array
                            (
                                [adminLabel] => fname
                                [id] => 5

                            )

                        [3] => Array
                            (
                                [adminLabel] => sign
                                [id] => 1

                            )

                    )

我需要将数组字段键设为 the[fields] [adminLabel]并将值设为[lead] [#].

所以在这个例子中,数组将有 key=value

formname = fstory
fname = trtr
hisher = his
sign = 508b38ee02f502.23680245.png

有意义吗?可能的?

4

1 回答 1

1

尝试这个。它未经测试。

$result_values  = $array['lead'];
$results        = array();
foreach ($array['form']['fields'] as $value) {
  if (is_array($value)) {
    $results[$value['adminLabel']] = $result_values[$value['id']];
  }  
}
print_r($results);
于 2012-10-27T02:11:03.357 回答