-3

我怎样才能制作这个数组:

Array
(
    [Qualifications] => Array
        (
            [name] => Array
                (
                    [0] => 1
                    [1] => 2
                )

            [description] => Array
                (
                    [0] => 1
                    [1] => 2
                )
)

看起来像这个数组?

Array
(
   [Qualifications] => Array
        (
            Array [0] =>
                (
                    [name]=> 1
                    [description] => 1
                )

            Array [1]
                (
                    [name] => 2
                    [descrition] => 2
                )
       )
)

它是通过带有 jquery 的表单字段生成的,然后发送回我的服务器。

4

1 回答 1

2

我会做这样的事情:

/**
 * @param array $bar bar is the qualification array containing (0=>'name' => array(), description => array()
 * @return array
 */
function foo(array $bar = array()){
    $finalArray = array();

    foreach($bar as $key => $value){
        foreach($value as $innerKey => $innerValue){
             $finalArray[$innerKey][$key] = $innerValue;
        }
    }
    return $finalArray;
}

所以你通过内部数组(什么是资格),你所要做的就是在最后把它放回资格。

编辑:没有功能:

$baseArray = array(Qualifications => array('name' => array(1,2), 'description' => array(1,2)));    

$bar = $baseArray['Qualifications'];

$transformedArray = array();
foreach($bar as $key => $value){
        foreach($value as $innerKey => $innerValue){
             $transformedArray [$innerKey][$key] = $innerValue;
        }
    }
$theArrayYouWant = array('Qualification' => $transformedArray);
于 2012-08-17T15:42:57.307 回答