{"id":321,"date":"2018-01-11T09:47:28","date_gmt":"2018-01-11T09:47:28","guid":{"rendered":"http:\/\/mddir.com\/how-to\/?p=321"},"modified":"2018-01-11T09:47:28","modified_gmt":"2018-01-11T09:47:28","slug":"php-functions-returning-values","status":"publish","type":"post","link":"https:\/\/www.mddir.com\/how-to\/php-functions-returning-values\/","title":{"rendered":"PHP Functions &#8211; Returning values"},"content":{"rendered":"<p>The function is used to return the value of the statement.<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>[php]&lt;?php<br \/>\nfunction sum($x, $y) {<br \/>\n    $z = $x + $y;<br \/>\n    return $z;<br \/>\n}<\/p>\n<p>echo &quot;5 + 10 = &quot; . sum(5, 10) . &quot;&lt;br&gt;&quot;;<br \/>\necho &quot;7 + 13 = &quot; . sum(7, 13) . &quot;&lt;br&gt;&quot;;<br \/>\necho &quot;2 + 4 = &quot; . sum(2, 4);<br \/>\n?&gt;[\/php]<\/p>\n<p>In the above function statement, first, we have to add the two variables <code>$x<\/code> and <code>$y<\/code> and return the sum in the return value <code>$z<\/code>. We will be using the return value in the echo statement.<\/p>\n<p>In the echo statement, we are asking php script to sum the values and return the variable <code>$z<\/code>.<\/p>\n<p>The above statement will generate the following result.<\/p>\n<p><code>5 + 10 = 15<br \/>\n7 + 13 = 20<br \/>\n2 + 4 = 6<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The function is used to return the value of the statement. Example [php]&lt;?php function sum($x, $y) { $z = $x + $y; return $z; }<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-321","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/321","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/comments?post=321"}],"version-history":[{"count":1,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/321\/revisions"}],"predecessor-version":[{"id":322,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/321\/revisions\/322"}],"wp:attachment":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/media?parent=321"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/categories?post=321"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/tags?post=321"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}