{"id":1363,"date":"2018-01-19T19:22:45","date_gmt":"2018-01-19T19:22:45","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/variable-variables\/"},"modified":"2018-01-19T19:24:44","modified_gmt":"2018-01-19T19:24:44","slug":"variable-variables","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/variable-variables\/","title":{"rendered":"Variable Variables"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Robert Berkowitz<\/div>\n<div class=\"\">on September 28, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/robert.jpg\" class=\"articleAuthorImg\" alt=\"picture of Robert\" height=\"116\" width=\"100\" align=\"left\"\/><\/p>\n<div class=\"articlePara\">\nDuring a recent project I discovered a totally new concept in programming for myself,<br \/>\nvariable variables.  I needed to update multiple records from one page.  After banging<br \/>\nmy head on the wall for quite some time, I stumbled across the variable variable and<br \/>\nall my troubles went away!<\/div>\n<h2>Introduction<\/h2>\n<div class=\"articlePara\">\nSo, just what the heck is a variable variable anyway?  According to the PHP manual,<br \/>\na variable variable takes the value of a variable and treats that as the name of a<br \/>\nvariable.  While this may seem pretty straightforward, it can be a little confusing<br \/>\nwith so many uses of the word &#8220;variable&#8221; in one sentence.  What the definition simply<br \/>\nstates is that you can set a variable &#8212; x equals this &#8212; and then set the variable<br \/>\nvariable, meaning you set the value of x as a new variable of x.  In this example,<br \/>\nthe variable this would equal is cake.  In PHP, this would be denoted as follows:<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p>$x\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #DD0000\">\"this\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>$<\/span><span style=\"color: #0000BB\">$x\u00a0<\/span><span style=\"color: #007700\">=\u00a0<\/span><span style=\"color: #DD0000\">\"is\u00a0cake\"<\/span><span style=\"color: #007700\">;<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font>\t<\/div>\n<div class=\"articlePara\">\nThe $$ is the syntax used in PHP for a variable variable.  I can now call the two variables $x and $$x two ways.<\/div>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #007700\">echo\u00a0<\/span><span style=\"color: #DD0000\">\"$x\u00a0${$x}\"<\/span><span style=\"color: #007700\">;<\/p>\n<p><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<p>\u00a0<\/p>\n<div class=\"articlePhpEx\">\n<font face=\"courier\"><code><span style=\"color: #000000\"><\/p>\n<p><span style=\"color: #0000BB\">&lt;?php<\/p>\n<p><\/span><span style=\"color: #007700\">echo\u00a0<\/span><span style=\"color: #DD0000\">\"$x\u00a0$this\"<\/span><span style=\"color: #007700\">;<br \/>\n<br \/>\u00a0\u00a0\u00a0\u00a0<br \/>\n<br \/><\/span><span style=\"color: #0000BB\">?&gt;<br \/>\n<br \/><\/span><br \/>\n<\/span><br \/>\n<\/code><\/font><\/div>\n<div class=\"articlePara\">\nBoth of these will return the string &#8220;this is cake&#8221;.  Notice that $$x is written as ${$x}<br \/>\nin echo.  This lets PHP know that you are using the variable $$x and not $ and $x.<\/div>\n<div class=\"articlePara\">\nStill scratching your head?  Or maybe you get it, but want a more in depth and actually<br \/>\nuseful example?  In the next section I will show you how variable variables may be used<br \/>\nto edit multiple records on one page.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">1<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"robert200009284658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"robert200009289ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"robert200009284658.html?page=2\">Next Page \u00bb<\/a><\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>By Robert Berkowitz on September 28, 2000 During a recent project I discovered a totally new concept in programming for myself, variable variables. I needed to update multiple records from one page. After banging my head on the wall for quite some time, I stumbled across the variable variable and&#8230; <a href=\"https:\/\/phpbuilder.com\/variable-variables\/\" class=\"readmore\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1363","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1363","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1363"}],"version-history":[{"count":1,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1363\/revisions"}],"predecessor-version":[{"id":2193,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1363\/revisions\/2193"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1363"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1363"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1363"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}