我完全被困在看似微不足道的問題上。php函數返回空字符串。 echo正確地打印字符串;
我有這樣的功能:
function findCategoryNameInTree($id, $tree) {
foreach($tree as $branch) {
if ($branch['category_id'] == $id) {
echo $branch['name'];//works
print_r($branch['name']);//works
//return($branch['name']); //returns nothing
return $branch['name'];//fix this line per feedback still no return value
} else {
if(count($branch['children']) > 0) {
findCategoryNameInTree($id,$branch['children']);
}
}
}
}
我想不出我爲什麼它不返回任何東西的生活。
請幫忙!
編輯 以下是我打電話給我的功能
//what I really want to do
$primgenre = findCategoryNameInTree($cat_id,$category_tree['children']);
//but this doesnt work either
echo $primgenre;
//nor this
print_r($pringenre);
你沒告訴我們這塊調用你的`findCategoryNameInTree`功能的代碼和它是如何你確定函數的返回值是錯誤的,而不是你對函數返回值的解釋。 – 2011-12-16 17:13:19