{"id":235,"date":"2009-07-27T23:00:08","date_gmt":"2009-07-27T22:00:08","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=235"},"modified":"2010-08-17T08:35:10","modified_gmt":"2010-08-17T07:35:10","slug":"method-add-two-numbers-3","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/method-add-two-numbers-3\/","title":{"rendered":"Method &#8211; Add Two numbers"},"content":{"rendered":"<p>This tutorial is using the same base code as <a title=\"Add two numbers\"  href=\"http:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/add-two-numbers-4\/\" target=\"_blank\">Add two numbers<\/a>, but with using the function addtwo, this takes two parameters $a and $b which are both set to 0 as the default value and returns the two values added together.  The answer part of the web page uses the function to add the two numbers together.<\/p>\n<p>The source code <\/p>\n<pre lang=\"php\">\r\n<?php\r\n       function addtwo($a = 0, $b = 0)\r\n       {\r\n              return ($a + $b);\r\n       }\r\n       $value1 = $_POST['value1'];\r\n       $value2 = $_POST['value2'];\r\n?>\r\n<html>\r\n       <title>PHP - Add two numbers<\/title>\r\n       <body>\r\n              <form action=\"addtwonumbers.php\" method=\"post\">\r\n                     <input type=\"text\" name=\"value1\" value=\"0\" \/>\r\n                     <input type=\"text\" name=\"value2\" value=\"0\" \/>\r\n                     <input type=\"submit\" value=\"Calculate values\"\/>\r\n              <\/form>\r\n              Answer : <?php echo addtwo($value1+$value2); ?>\r\n       <\/body>\r\n<\/html>\r\n<\/pre>\n<p>save as addtwonumbers_function.php, this program will function the same as the previous tutorial apart from the inner working will call the method.  The method programming allows for one method to be called multiple times, e.g. Within the example above there could be a method that was 5 lines in length and instead of writing the same 5 lines each time, you just write a method that is called.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial is using the same base code as Add two numbers, but with using the function addtwo, this takes two parameters $a and $b which are both set to 0 as the default value and returns the two values added together. The answer part of the web page uses the function to add the &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2009\/07\/27\/method-add-two-numbers-3\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Method &#8211; Add Two numbers<\/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":[18,19,398,403,400],"class_list":["post-235","post","type-post","status-publish","format-standard","hentry","category-php","tag-apache","tag-iis","tag-linux","tag-php","tag-windows"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/235","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=235"}],"version-history":[{"count":4,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions"}],"predecessor-version":[{"id":1163,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/235\/revisions\/1163"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}