मेरे पास एक विधि है जो डेटाबेस से एक संशोधित प्रीऑर्डर पेड़ ट्रांसवर्सेल पेड़ निकालती है, और कॉलबैक फ़ंक्शन का उपयोग करके फ़िल्टर करती है। उदाहरण के लिए:मुझे कॉलबैक को PHPDoc कैसे करना चाहिए?
/**
* Recursive function for building the Cas_Template_TreeNode.
*
* @static
* @param array $rows
* @param callback $filter A function to filter the tree by (return a value convertible to false to remove the item from the tree)
* @return array
*/
private static function MakeTreeGivenDbRows($rows, $filter = null)
{
if ($filter === null)
{
$filter = function($unused)
{
return true;
};
}
$result = array();
$childrenCount = 0;
for ($idx = 0; $idx < count($rows); $idx += $childrenCount + 1)
{
$current = $rows[$idx];
$childrenCount = self::ChildrenCountFromRow($current);
if (!$filter($current))
{
continue;
}
$childrenStartAt = $idx + 1;
$childRows = array_slice($rows, $childrenStartAt, $childrenCount);
$children = self::MakeTreeGivenDbRows($childRows, $filter);
$result[] = new Cas_Template_TreeNode(self::MakeNodeGivenDbRow($current), $children);
}
if (empty($result))
{
return null;
}
return $result;
}
मुझे यकीन है कि क्या phpdoc चर $filter
के लिए किया जाना चाहिए नहीं कर रहा हूँ - यह जो है मैं क्या इंगित किया है एक कॉलबैक, है, लेकिन मुझे यकीन है कि अगर सही है नहीं कर रहा हूँ।
इसके अलावा, गुणवत्ता (या उसके अभाव) इस कोड में पर कोई अन्य टिप्पणी की सराहना किया जाएगा :)
महान सवाल। – zerkms