-4

我有 2 个从数据库返回值的数据库查询,最简单的方法是什么。是否有一个 PHP 函数可以做到这一点,还是我必须使用循环?

$names = array(
        'det-1' => array('foo'),
        'det-2' => array('bar'),
        'det-3' => array('doe')
    );      

    $emails = array(
        'det-1' => array('foo@gmail.com'),
        'det-2' => array('bar@gmail.com'),
        'det-3' => array('doe@gmail.com')
    );

// 结果

    $details = array(
        'det-1' => array('foo', 'foo@gmail.com')
        'det-2' => array('bar', 'bar@gmail.com')
        'det-3' => array('doe', 'doe@gmail.com')
    );
4

2 回答 2

2

使用array_merge_recursive()

php > print_r(array_merge_recursive($names, $emails));
Array
(
    [det-1] => Array
        (
            [0] => foo
            [1] => foo@gmail.com
        )

    [det-2] => Array
        (
            [0] => bar
            [1] => bar@gmail.com
        )

    [det-3] => Array
        (
            [0] => doe
            [1] => doe@gmail.com
        )

)
于 2013-05-20T13:01:58.863 回答
0

您可以使用array_merge_recursive

$newArray = array_merge_recursive($names, $emails);
于 2013-05-20T13:01:20.550 回答