0

我有一个看起来像这样的数组 POST

Array
(
[ponumber] => 111111
[man_part_number] => Array
    (
        [0] => 11C2555
        [1] => 11C2555
        [2] => 11C2555
        [3] => 11C2555
    )

[model] => Array
    (
        [0] => FORMS PRINTER 2500 SERIES
        [1] => FORMS PRINTER 2500 SERIES
        [2] => FORMS PRINTER 2500 SERIES
        [3] => FORMS PRINTER 2500 SERIES
    )

[damaged] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 0
        [3] => 0
    )

[serial_number] => Array
    (
        [0] => CNCQ202070
        [1] => CNCQ210800
        [2] => MY5203B1KQ
        [3] => CN1863Q0PQ
    )

[skid] => Array
    (
        [0] => 1
        [1] => 2
        [2] => 3
        [3] => 4
    )

[submit] => Attach this serial number list to PO#111111
)

我需要将数组组合成

Array
(
[man_part_number] => Array
    (
        [0] = > 11C2555
    )
[model] => Array
    (
        [0] => FORMS PRINTER 2500 SERIES
    )
[damaged] => Array
    (
        [0] => 0
    )
[serial_number] => Array
    (
        [0] => CNCQ202070
    )
[skid] => Array
    (
        [0] => 1
    )
[ponumber] => Array
    (
        [0] => 111111
    }
}

依此类推,以便所有 [0] 也组合为 [1]、[2] 和 [3],但 ponumber 也需要添加到每个数组中,并且对于所有 4 个数组都是相同的。

4

2 回答 2

0

您可以使用MultipleIterator

$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ALL|MultipleIterator::MIT_KEYS_ASSOC);
$mi->attachIterator(new ArrayIterator($data['man_part_number']),"man_part_number");
$mi->attachIterator(new ArrayIterator($data['model']),"model");
$mi->attachIterator(new ArrayIterator($data['damaged']),"damaged");
$mi->attachIterator(new ArrayIterator($data['serial_number']),"serial_number");
$mi->attachIterator(new ArrayIterator($data['skid']),"skid");

echo "<pre>";
foreach ($mi as $member) {
    print_r($member);
}

输出

Array
(
    [man_part_number] => 11C2555
    [model] => FORMS PRINTER 2500 SERIES
    [damaged] => 0
    [serial_number] => CNCQ202070
    [skid] => 1
)
Array
(
    [man_part_number] => 11C2555
    [model] => FORMS PRINTER 2500 SERIES
    [damaged] => 0
    [serial_number] => CNCQ210800
    [skid] => 2
)
Array
(
    [man_part_number] => 11C2555
    [model] => FORMS PRINTER 2500 SERIES
    [damaged] => 0
    [serial_number] => MY5203B1KQ
    [skid] => 3
)
Array
(
    [man_part_number] => 11C2555
    [model] => FORMS PRINTER 2500 SERIES
    [damaged] => 0
    [serial_number] => CN1863Q0PQ
    [skid] => 4
)

观看现场演示

于 2013-01-08T09:21:16.687 回答
0
$array = array_map('current', $array[0]);
于 2013-01-08T08:59:31.187 回答