{"id":414,"date":"2009-11-23T15:58:15","date_gmt":"2009-11-23T15:58:15","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=414"},"modified":"2009-11-23T15:58:35","modified_gmt":"2009-11-23T15:58:35","slug":"call-a-function","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/11\/23\/call-a-function\/","title":{"rendered":"Call a function"},"content":{"rendered":"<p>Lets just say that you are writing a template program and you want to add into a array of function calls, which you can add to as well on-the-fly.   Within PHP you can use a function called <a href=\"http:\/\/uk2.php.net\/call_user_func\">call_user_func<\/a> which allows you to call a function using a stringed parameter in the first parameter and the next parameter(s) (if you wish to pass more than one parameter) is next.  Hopefully the below will demonstrate better.<\/p>\n<pre lang=\"php\">\r\n<?php\r\n  function test($var)\r\n  {\r\n    echo \"test : \" . $var;\r\n  }\r\n\r\n  function example($var)\r\n  {\r\n    echo \"example : \" . $var;\r\n  }\r\n\r\n  $funarr = array(array(\"test\", \"codingfriends\"), array(\"example\", \"was here\"));\r\n\r\n  foreach ($funarr as $funarr_call)\r\n  {\r\n    call_user_func($funarr_call[0], $funarr_call[1]);\r\n    echo \"<br\/>\";\r\n  }\r\n?>\r\n<\/pre>\n<p>and the output would be<\/p>\n<pre lang=\"html\">\r\ntest : codingfriends\r\nexample : was here\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lets just say that you are writing a template program and you want to add into a array of function calls, which you can add to as well on-the-fly. Within PHP you can use a function called call_user_func which allows you to call a function using a stringed parameter in the first parameter and the &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/11\/23\/call-a-function\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Call a function<\/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":[],"class_list":["post-414","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/414","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=414"}],"version-history":[{"count":2,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":416,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions\/416"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}