我如何创建自定义数组

时间:2015-06-22 12:37:52

标签: php arrays

Array
(
    [0] => Array
        (
            [418] => Albania
        )

    [1] => Array
        (
            [5] => Andorra
        )

    [2] => Array
        (
            [6] => Angola
        )

    [3] => Array
        (
            [8] => Antigua and Barbuda
        )

    [4] => Array
        (
            [9] => Argentina
        )

    [5] => Array
        (
            [486] => Armenia
        )
);

如何从上面的数组中获取如下所示的数组

Array
    (
        [418] => Albania
        [5] => Andorra
        [6] => Angola
        [8] => Antigua and Barbuda
        [9] => Argentina
        [486] => Armenia
    )

1 个答案:

答案 0 :(得分:0)

<?php

$a = [[418=>'Albania'],[5=>'Andorra'],[6=>'Angola'],[8=>'Antigua and Barbuda'],[4=>'Argentina'],[486=>'Armenia']];
$b = array();

foreach($a as $aEntry) {
    $b += $aEntry;
}

print_r($b);

如果国家/地区代码是唯一的,这将有效。