{"id":279,"date":"2018-01-04T12:22:41","date_gmt":"2018-01-04T12:22:41","guid":{"rendered":"http:\/\/mddir.com\/how-to\/?p=279"},"modified":"2018-01-04T12:22:52","modified_gmt":"2018-01-04T12:22:52","slug":"use-global-keyword","status":"publish","type":"post","link":"https:\/\/www.mddir.com\/how-to\/use-global-keyword\/","title":{"rendered":"Use Global Keyword"},"content":{"rendered":"<p>The Global keyword is used to get the information of the variable within the function.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>[php]&lt;?php<br \/>\n$x = 5;<br \/>\n$y = 10;<\/p>\n<p>function mddir() {<br \/>\n    global $x, $y;<br \/>\n    $y = $x + $y;<br \/>\n}<br \/>\nmddir();  \/\/ run function<br \/>\necho $y; \/\/ output the new value for variable $y<br \/>\n?&gt;[\/php]<\/p>\n<p>In above php code, we have declared the global variable <code>$x<\/code> and $y and provided the value of 5 &#038; 10 respectively.  To get this value in the php function we have to use the word &#8220;<code>global<\/code>&#8221; as a keyword to get the information from the <code>$x<\/code> and <code>$y<\/code>. <\/p>\n<p>The word global is reserved as a Global keyword in the php liabrary. you can use the keyword anywhere in the php script to fetch the value of the global variables.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Global keyword is used to get the information of the variable within the function. Example: [php]&lt;?php $x = 5; $y = 10; function mddir()<\/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-279","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/279","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=279"}],"version-history":[{"count":2,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":281,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/279\/revisions\/281"}],"wp:attachment":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/media?parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/categories?post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/tags?post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}