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' => $deviceName,
'Device' => $d[0],
$namesArray[0] => $d[1],
$namesArray[1] => $d[2],
$namesArray[2] => $d[3],
$namesArray[3] => $d[4],
$namesArray[4] => $d[5],
$namesArray[5] => $d[6],
$namesArray[6] => $d[7],
$namesArray[7] => $d[8],
$namesArray[8] => $d[9],
$namesArray[9] => $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] => Array
(
[0] => iPhone 4 (4, 4S)
[1] => iOS
[2] => 3.5
[3] => 8.9
[4] => 640
[5] => 960
[6] => 320
[7] => 326
[8] => 200% XHDPI
[9] => 2 : 3
[10] => 8.8
)
[1] => Array
(
[0] => iPhone 5 (5c, 5s)
[1] => iOS
[2] => 4.0
[3] => 10.0
[4] => 640
[5] => 1136
[6] => 320
[7] => 326
[8] => 200% XHDPI
[9] => 40 : 71
[10] => 7.9
)
)
and $deviceName field which can be 'Phone', 'Tablet' or 'Monitor'.
This gives the output
[0] => Array
(
[Device Type] => Phone
[Device] => iPhone 4 (4, 4S)
[Operating System] => iOS
[Physical Size] => 8.9
[Width] => 640
[Height] => 960
[Device-width] => 320
[Px Per Inch] => 326
[Px Density] => 200% XHDPI
[Aspect Ratio] => 2 : 3
[Popularity] => 8.8
)
[1] => Array
(
[Device Type] => Phone
[Device] => iPhone 5 (5c, 5s)
[Operating System] => iOS
[Physical Size] => 10.0
[Width] => 640
[Height] => 1136
[Device-width] => 320
[Px Per Inch] => 326
[Px Density] => 200% XHDPI
[Aspect Ratio] => 40 : 71
[Popularity] => 7.9
)