1

我有这个函数应该返回一个数组,但它返回的是 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);
    }
}
4

1 回答 1

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);
    }
}
于 2013-09-29T21:29:10.030 回答