Join two arrays into a single one I put together a function to sort out values that I am getting from a curl request for different 'devices', it works as is, I am only wondering if there is an easier way to to this.  

function convert($deviceName, $namesArray, $devicesArray) {
    $result = array();
    foreach ($devicesArray as $d) {
        $result [] = [
            'Device Type' =&gt; $deviceName,
            'Device' =&gt; $d[0],
            $namesArray[0] =&gt; $d[1],
            $namesArray[1] =&gt; $d[2],
            $namesArray[2] =&gt; $d[3],
            $namesArray[3] =&gt; $d[4],
            $namesArray[4] =&gt; $d[5],
            $namesArray[5] =&gt; $d[6],
            $namesArray[6] =&gt; $d[7],
            $namesArray[7] =&gt; $d[8],
            $namesArray[8] =&gt; $d[9],
            $namesArray[9] =&gt; $d[10]
        ];
    }
    return $result;
}


it takes in the following:

$namesArray = [ Operating System, Physical Size, Physical Size, Width, Height, Device-width, Px Per Inch, Px Density, Aspect Ratio, Popularity];

$devicesArray = 
Array
(

    [0] =&gt; Array
            (
            [0] =&gt; iPhone 4 (4, 4S)
            [1] =&gt; iOS
            [2] =&gt; 3.5
            [3] =&gt; 8.9
            [4] =&gt; 640
            [5] =&gt; 960
            [6] =&gt; 320
            [7] =&gt; 326
            [8] =&gt; 200% XHDPI
            [9] =&gt; 2 : 3
            [10] =&gt; 8.8
            )

    [1] =&gt; Array
            (
            [0] =&gt; iPhone 5 (5c, 5s)
            [1] =&gt; iOS
            [2] =&gt; 4.0
            [3] =&gt; 10.0
            [4] =&gt; 640
            [5] =&gt; 1136
            [6] =&gt; 320
            [7] =&gt; 326
            [8] =&gt; 200% XHDPI
            [9] =&gt; 40 : 71
            [10] =&gt; 7.9
            )
)

 and $deviceName field which can be 'Phone', 'Tablet' or 'Monitor'.


This gives the output 

[0] =&gt; Array
        (
            [Device Type] =&gt; Phone
            [Device] =&gt; iPhone 4 (4, 4S)
            [Operating System] =&gt; iOS
            [Physical Size] =&gt; 8.9
            [Width] =&gt; 640
            [Height] =&gt; 960
            [Device-width] =&gt; 320
            [Px Per Inch] =&gt; 326
            [Px Density] =&gt; 200% XHDPI
            [Aspect Ratio] =&gt; 2 : 3
            [Popularity] =&gt; 8.8
        )

    [1] =&gt; Array
        (
            [Device Type] =&gt; Phone
            [Device] =&gt; iPhone 5 (5c, 5s)
            [Operating System] =&gt; iOS
            [Physical Size] =&gt; 10.0
            [Width] =&gt; 640
            [Height] =&gt; 1136
            [Device-width] =&gt; 320
            [Px Per Inch] =&gt; 326
            [Px Density] =&gt; 200% XHDPI
            [Aspect Ratio] =&gt; 40 : 71
            [Popularity] =&gt; 7.9
        )
Change $devicesArray to $devices.  It is obvious enough that each device would contain an array of information.
Change $namesArray to $deviceFields it is more meaningful.
Change $deviceName to $deviceType. $deviceName seems to be misleading.
Use $device instead of $d in the foreach loop, it is more meaningful.
'Device' is a field and should be the first field in $deviceFields. This is required for the following improvement.
Use array functions to combine the arrays:
array('Device Type' =&gt; $deviceType]) + array_combine($deviceFields, $device).


The function then becomes:

function convert($deviceType, $deviceFields, $devices) {
    $result = [];

    foreach ($devices as $device) {
        $result[] =
            ['Device Type' =&gt; $deviceType] +
            array_combine($deviceFields, $device);
    }

    return $result;
}