combine and return contents of multiple cached files

Currently I have separate cached files for each of our YouTube playlists. The videos from each playlist is retrieved as needed by sending the playlist title to the Video function below.

Now, rather than just retrieving videos from one playlist, I would like to return all videos from specific playlists. I thought this could be done by looping through an array of playlists I was interested in, but it's breaking the page and giving me an array error "Fatal error: Cannot use object of type stdClass as array" (See function Videos_test). Any help you could provide would be greatly appreciated.

    function Videos($tag)
    {
        $cachefile = $tag;
        $videos = array();
        //Check the cache file
        if(file_exists($this->cachefile_directory . $cachefile)){
            $data = @file_get_contents($this->cachefile_directory . $cachefile);
            $data = json_decode($data);
            return $data->{"videos"};
        } else {
            return false;
        }
        
    } 

    function Videos_test($tag)
    {
	$cachefileArr = array('List 1', 'List 3', 'List 5');
        $videos = array();
        foreach($cachefileArr as $cachefile)
        {        
            //Check the cache file
            if(file_exists($this->cachefile_directory . $cachefile)){
                $data = @file_get_contents($this->cachefile_directory . $cachefile);
                $data = json_decode($data);
                $list = $data['videos'];
                $videoData .= $list;                
            }
        }
        return $videoData;
    }

Open in new window

LVL 1
jej07Asked:
Who is Participating?
 
jej07Author Commented:
Thank you for your response. I approached this from a different angle and no longer need to combine the playlists.
0
 
Ray PaseurCommented:
Is there more to this?  Maybe if we have a complete PHP script and the line number we can go after the problem with some test cases.
0
 
jej07Author Commented:
Went a different route.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.