Merge values from different arrays to one with the same key

前端 未结 3 656
南笙
南笙 2020-12-12 07:38

I have two arrays:

Array
(
    [0] => 5
    [1] => 4
)
Array
(
    [0] => BMW
    [1] => Ferrari
)

And I would like to have tha

3条回答
  •  不知归路
    2020-12-12 08:18

    As to @splash58 comment:

    You can use array-map. Here an example:

    $array = [["5", "4"], ["BMW", "Ferrari"]];
    $res = array_map(null, ...$array);
    

    Now res will contain:

    Array
    (
        [0] => Array
            (
                [0] => 5
                [1] => BMW
            )
        [1] => Array
            (
                [0] => 4
                [1] => Ferrari
            )
    )
    

    If the array in 2 different var you can use:

    $res= array_map(null, ["5", "4"], ["BMW", "Ferrari"]);
    

提交回复
热议问题