3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $ANDROID_MAPPING_ARRAY = array(1 => '1.0', 2 => '1.1', 3 => '1.5', 4 => '1.6', 5 => '2.0', 6 => '2.0.1', 7 => '2.1.x', 8 => '2.2.x', 9 => '2.3.2', 10 => '2.3.4', 11 => '3.0.x', 12 => '3.1.x', 13 => '3.2', 14 => '4.0.1', 15 => '4.0.4', 16 => '4.1.1', 17 => '4.2.2', 18 => '4.3', 19 => '4.4' ); $userAgent = 'ZooskAndroid/142 (Linux; U; Android 4.4; en-US; XT1030; Build/SU2-3.3)'; $agentParts = explode(',', $userAgent); $androidInfo = array(); foreach ($agentParts as $agentPart) { $partInfo = explode('/', $agentPart); if (count($partInfo) == 3) { if (strcmp($partInfo[0], 'Android') == 0) { $androidInfo[0] = $partInfo[0]; // case 81288: Lookup to map Android API version to Android OS version $versionInfo = explode('.', $partInfo[2]); if (!empty($versionInfo)) { $androidInfo[1] = $ANDROID_MAPPING_ARRAY[$versionInfo[0]]; } if (empty($androidInfo[1])) { $androidInfo[1] = $partInfo[2]; } if (count($androidInfo) > 1) { break; //return $androidInfo; } } } } print_r($androidInfo);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( )