Nested function: Difference between revisions
Content added Content deleted
(added perl) |
(added php) |
||
Line 85: | Line 85: | ||
print makeList(". ");</lang> |
print makeList(". ");</lang> |
||
=={{header|PHP}}== |
|||
{{works with|PHP|5.3+}} |
|||
<lang php><? |
|||
function makeList($separator) { |
|||
$counter = 1; |
|||
$makeItem = function ($item) use ($separator, &$counter) { |
|||
return $counter++ . $separator . $item . "\n"; |
|||
}; |
|||
return $makeItem("first") . $makeItem("second") . $makeItem("third"); |
|||
} |
|||
echo makeList(". "); |
|||
?></lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |