php - Returning Multiple Variables with isset() -
i have bit of code returns user agent, running through function parse it. code have used returns 1 variable parsing function (there three: 'platform' 'browser' 'version'):
function my_get_user_agent($value) { $browser = parse_user_agent(); return isset($browser['platform']) ? $browser['platform'] : ''; }
while code works return platform of user agent, need append return 3 variables in function. changed first half of code assume correct:
return isset($browser['platform'], $browser['browser'], $browser['version'])? $browser['platform'] : '';
i unsure, however, need return 3 values. suggestions?
you can return entire array:
return $browser;
then access values later:
$browser['platform']; $browser['browser']; $browser['version'];
reading question again, seem want ensure value set. can this:
foreach($browser $value) { if(isset($value)) { $data[] = $value; } } return $data;
now data contain platform, browser, , version.
Comments
Post a Comment