{"id":1812,"date":"2014-04-28T21:30:41","date_gmt":"2014-04-28T20:30:41","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1812"},"modified":"2014-04-28T21:30:41","modified_gmt":"2014-04-28T20:30:41","slug":"lambda","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2014\/04\/28\/lambda\/","title":{"rendered":"Lambda"},"content":{"rendered":"<p>After allot of coding of late, thought that I would place online a great syntax called lambda which allows you to do assign functions to a variable that is callable!!.  So the functions like <a href=\"http:\/\/www.php.net\/manual\/en\/function.preg-replace-callback.php\" title=\"pref_replace_callback\" target=\"_blank\">pref_replace_callback<\/a> that has a function as the parameter to be used if any matches are meet.<\/p>\n<p>So for a example, I think that source code always works the best.<\/p>\n<pre lang=\"php\">\r\nfunction newFun ($name) { \r\n\t$call = function ($second) use ($name) {\r\n\t\treturn $second . $name; \r\n\t};\r\n\treturn $call($name);\r\n\t\r\n}\r\n\r\necho newFun(\"hi there\");\r\n<\/pre>\n<p>and the output would be<\/p>\n<pre lang=\"bash\">\r\nhi therehi there\r\n<\/pre>\n<p>What it is doing is assigning to the <strong>$call<\/strong> variable is the actual function call! which is able to be able to pass in via the parameters a parameter but also to &#8220;use&#8221; local variables within the function.  The $name is passed in to the newFun function and is then use[d] within the lambda function, how cool is that!.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After allot of coding of late, thought that I would place online a great syntax called lambda which allows you to do assign functions to a variable that is callable!!. So the functions like pref_replace_callback that has a function as the parameter to be used if any matches are meet. So for a example, I &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2014\/04\/28\/lambda\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Lambda<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[393],"class_list":["post-1812","post","type-post","status-publish","format-standard","hentry","category-php","tag-lambda"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1812"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1812\/revisions"}],"predecessor-version":[{"id":1813,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1812\/revisions\/1813"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}