leke Posted November 15, 2012 Share Posted November 15, 2012 How can I store the returned result of a function that outputs an array, so I can pass parts of it to other functions? As you can se, this function will have different output each time it is called as a function. Thanks. <?php $apikey = '1234567890'; $movie_title_file = "5000-movies.txt"; $access_movie_title_db = file_get_contents($movie_title_file); $movie_title_db = explode("\n", $access_movie_title_db); function getMovieObject() { global $apikey, $movie_title_file, $access_movie_title_db, $movie_title_db; $random_index = array_rand($movie_title_db,1); $query = $movie_title_db[$random_index]; // end result is a film title to query. $url_title = urlencode($query); // make sure to url encode an query parameters // Taken from the RT API... // construct the query with our apikey and the query we want to make $endpoint = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $url_title; // setup curl to make a call to the endpoint $session = curl_init($endpoint); // indicates that we want the response back curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // exec curl and get the data back $data = curl_exec($session); // remember to close the curl session once we are finished retrieveing the data curl_close($session); // decode the json data to make it easier to parse the php $search_results = json_decode($data); if ($search_results === NULL) die('Error parsing json'); $movies = $search_results->movies; return $movies; } Quote Link to comment https://forums.phpfreaks.com/topic/270731-how-can-i-store-the-returned-result-of-a-function/ Share on other sites More sharing options...
Muddy_Funster Posted November 15, 2012 Share Posted November 15, 2012 $movie = getMovieObject(); Quote Link to comment https://forums.phpfreaks.com/topic/270731-how-can-i-store-the-returned-result-of-a-function/#findComment-1392650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.