{"id":53,"date":"2010-06-20T15:45:00","date_gmt":"2010-06-20T15:45:00","guid":{"rendered":"http:\/\/www.codeboss.in\/web-funda\/?p=53"},"modified":"2010-06-20T15:45:00","modified_gmt":"2010-06-20T15:45:00","slug":"double-dollar-or-variable-variables-in-php","status":"publish","type":"post","link":"https:\/\/codeboss.in\/web-funda\/2010\/06\/20\/double-dollar-or-variable-variables-in-php\/","title":{"rendered":"Double Dollar Or Variable Variables In PHP"},"content":{"rendered":"<p>Apart from the normal variables in PHP, which we write like <b>$a<\/b>, there is also a variable variable which is written like <b>$$a<\/b>. <\/p>\n<p>The problem is when someone wants to search what does this double dollar mean, they do not know how to search. Well searching will be a lot easier if they search by <b>variable variables in PHP<\/b>, and the best resource as always is at <a href=\"http:\/\/www.php.net\/manual\/en\/language.variables.variable.php\" target=\"_blank\" rel=\"noopener\">php.net<\/a>.<\/p>\n<p>To give a short explanation here it is used to give variable \/ dynamic names to variables.<\/p>\n<p>Lets see a quick example. Say a value increases by a fixed amount everyday of the week. To enter and output the value for each day the code can be like &#8211;<\/p>\n<pre class=\"brush: php; html-script: true\">$dyn = array(\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\", \"Friday\",\"Saturday\");<br \/>$i=0;<br \/>foreach($dyn as $eachDyn){<br \/> $$eachDyn = $i;<br \/> $i+=2;<br \/>}<br \/>foreach($dyn as $eachDyn){<br \/> echo $eachDyn .\" = \".$$eachDyn;<br \/>}<br \/><\/pre>\n<p>If the fixed amount changes later we need to just change the line $i+=2; to maybe say $i+=5; and that would be sufficient. No need to change each day individually.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Apart from the normal variables in PHP, which we write like $a, there is also a variable variable which is written like $$a. The problem is when someone wants to search what does this double dollar mean, they do not know how to search. Well searching will be a lot easier if they search by&hellip; <a class=\"more-link\" href=\"https:\/\/codeboss.in\/web-funda\/2010\/06\/20\/double-dollar-or-variable-variables-in-php\/\">Continue reading <span class=\"screen-reader-text\">Double Dollar Or Variable Variables In PHP<\/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":[1],"tags":[57],"class_list":["post-53","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-php","entry"],"_links":{"self":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":0,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"wp:attachment":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}