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