php - Multiple responses from function -
i'm trying have function return multiple results in array(?).
so instead of running lookup("354534", "name");
, lookup("354534", "date");
mutiple times different results, how can return both name & date function, echo out have use function once?
function lookup($data, $what) { $json = file_get_contents("http://site.com/".$data.".json"); $output = json_decode($json, true); echo $output['foo'][''.$what.'']; }
thanks!
have function return whole json result:
function lookup($data) { $json = file_get_contents("http://site.com/".$data.".json"); $output = json_decode($json, true); return $output["foo"]; }
then can
$result = lookup("354534"); echo $result["name"]; echo $result["date"];
this idea, because otherwise, you'll make (slow) file_get_contents request multiple times, want avoid.
Comments
Post a Comment