function应该返回数组但是返回NULL

时间:2013-09-29 21:27:03

标签: php

我有这个函数应该返回一个数组,但它返回NULL。我认为它可能与它生成的数组的大小有关,因为有时它确实可以正常工作。我试图在返回之前做一个var_dump,它总是显示我需要的数组,但是函数输出的var_dump只显示NULL。

function getAllUploads($videoFeed, $videos = array(), $counter = 1){
    foreach($videoFeed as $videoEntry){
        if($videoEntry->extensionElements[6]->extensionAttributes['permission']['value'] == "allowed"){
            $videos[] = array("videoID" => $videoEntry->getVideoId(), "uploaded" => ytToMySQLDateTime($videoEntry->getPublished()->getText())); //date('Y-m-d H:i:s', $videoEntry->getPublished()->getText())
        }
        $counter++;
    }

    try{
        $videoFeed = $videoFeed->getNextFeed();
    }catch(Zend_Gdata_App_Exception $e){
        return $videos;
    }

    if($videoFeed){
        getAllUploads($videoFeed, $videos, $counter);
    }
}

1 个答案:

答案 0 :(得分:2)

您应该在最后if()语句

中返回该函数
function getAllUploads($videoFeed, $videos = array(), $counter = 1){
    foreach($videoFeed as $videoEntry){
        if($videoEntry->extensionElements[6]->extensionAttributes['permission']['value'] == "allowed"){
            $videos[] = array("videoID" => $videoEntry->getVideoId(), "uploaded" => ytToMySQLDateTime($videoEntry->getPublished()->getText())); //date('Y-m-d H:i:s', $videoEntry->getPublished()->getText())
        }
        $counter++;
    }

    try{
        $videoFeed = $videoFeed->getNextFeed();
    }catch(Zend_Gdata_App_Exception $e){
        return $videos;
    }

    if($videoFeed){
        return getAllUploads($videoFeed, $videos, $counter);
    }
}