<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1702728768607313896</id><updated>2024-09-01T23:03:01.156-07:00</updated><title type='text'>learn php script</title><subtitle type='html'>PHP can be used on all major operating systems</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default?start-index=26&amp;max-results=25'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-8040141182390450142</id><published>2009-01-08T19:26:00.000-08:00</published><updated>2009-01-08T19:27:12.491-08:00</updated><title type='text'>Control Structures</title><content type='html'>&lt;h1&gt;&lt;a name=&quot;language.control-structures&quot;&gt;Control Structures&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;TOC&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;else&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;elseif&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;Alternative syntax for  control structures &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;while&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;do-while&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;for&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;foreach&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;break&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;continue&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;switch&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class=&quot;literal&quot;&gt;declare&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;return &lt;/dt&gt;&lt;dt&gt;&lt;b class=&quot;function&quot;&gt;require()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class=&quot;function&quot;&gt;include()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class=&quot;function&quot;&gt;require_once()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class=&quot;function&quot;&gt;include_once()&lt;/b&gt;&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt; &lt;p&gt;Any PHP script is built out of a series of statements. A statement can be an  assignment, a function call, a loop, a conditional statement of even a statement  that does nothing (an empty statement). Statements usually end with a semicolon.  In addition, statements can be grouped into a statement-group by encapsulating a  group of statements with curly braces. A statement-group is a statement by  itself as well. The various statement types are described in this chapter. &lt;/p&gt; &lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;control-structures.if&quot;&gt;&lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt;&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; construct is one of the most important  features of many languages, PHP included. It allows for conditional execution of  code fragments. PHP features an &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; structure that is  similar to that of C:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4627&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;?php&lt;br /&gt;if (expression)&lt;br /&gt;   statement&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;As described in the section about  expressions, &lt;var class=&quot;replaceable&quot;&gt;expr&lt;/var&gt; is evaluated to its Boolean  value. If &lt;var class=&quot;replaceable&quot;&gt;expr&lt;/var&gt; evaluates to &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, PHP will execute &lt;var class=&quot;replaceable&quot;&gt;statement&lt;/var&gt;, and if it evaluates to &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; - it&#39;ll ignore it. More information about what  values evaluate to &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; can be found in the &#39;Converting to  boolean&#39; section. &lt;/p&gt; &lt;p&gt;The following example would display &lt;samp class=&quot;computeroutput&quot;&gt;a is bigger  than b&lt;/samp&gt; if &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; is bigger than &lt;var class=&quot;varname&quot;&gt;$b&lt;/var&gt;:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4642&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if  (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a is  bigger than b&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;Often you&#39;d want to have more than one statement to be executed  conditionally. Of course, there&#39;s no need to wrap each statement with an &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; clause. Instead, you can group several statements into a  statement group. For example, this code would display &lt;samp class=&quot;computeroutput&quot;&gt;a is bigger than b&lt;/samp&gt; if &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; is  bigger than &lt;var class=&quot;varname&quot;&gt;$b&lt;/var&gt;, and would then assign the value of &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; into &lt;var class=&quot;varname&quot;&gt;$b&lt;/var&gt;:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4651&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if  (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)  {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a is bigger than  b&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;&lt;var class=&quot;literal&quot;&gt;If&lt;/var&gt; statements can be nested indefinitely within  other &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; statements, which provides you with complete  flexibility for conditional execution of the various parts of your program.  &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/8040141182390450142/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/control-structures.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/8040141182390450142'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/8040141182390450142'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/control-structures.html' title='Control Structures'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-1470231614734722489</id><published>2009-01-08T17:28:00.004-08:00</published><updated>2009-01-08T17:29:01.213-08:00</updated><title type='text'>Type Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.type&quot;&gt;Type Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP has a single type operator: &lt;var class=&quot;literal&quot;&gt;instanceof&lt;/var&gt;. &lt;var class=&quot;literal&quot;&gt;instanceof&lt;/var&gt; is used to determine whether a given object is of  a specified object class. &lt;/p&gt; &lt;p&gt;The &lt;var class=&quot;literal&quot;&gt;instanceof&lt;/var&gt; operator was introduced in PHP 5.  Before this time &lt;b class=&quot;function&quot;&gt;is_a()&lt;/b&gt;  was used but &lt;b class=&quot;function&quot;&gt;is_a()&lt;/b&gt; has  since been deprecated in favor of &lt;var class=&quot;literal&quot;&gt;instanceof&lt;/var&gt;. &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4609&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;programlisting&quot;&gt;&lt;?php&lt;br /&gt;class A { }&lt;br /&gt;class B { }&lt;br /&gt;&lt;br /&gt;$thing = new A;&lt;br /&gt;&lt;br /&gt;if ($thing instanceof A) {&lt;br /&gt;   echo &#39;A&#39;;&lt;br /&gt;}&lt;br /&gt;if ($thing instanceof B) {&lt;br /&gt;   echo &#39;B&#39;;&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;As &lt;var class=&quot;varname&quot;&gt;$thing&lt;/var&gt; is an &lt;b class=&quot;type&quot;&gt;object&lt;/b&gt; of type A, but  not B, only the block dependent on the A type will be executed: &lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;screen&quot;&gt;A&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;See also &lt;b class=&quot;function&quot;&gt;get_class()&lt;/b&gt; and &lt;b class=&quot;function&quot;&gt;is_a()&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/1470231614734722489/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/type-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/1470231614734722489'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/1470231614734722489'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/type-operators.html' title='Type Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3936507931107136635</id><published>2009-01-08T17:28:00.003-08:00</published><updated>2009-01-08T17:28:42.389-08:00</updated><title type='text'>Array Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.array&quot;&gt;Array Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4546&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-8. Array Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;$a + $b&lt;/td&gt; &lt;td&gt;Union&lt;/td&gt; &lt;td&gt;Union of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a == $b&lt;/td&gt; &lt;td&gt;Equality&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a and $b have the same key/value  pairs.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a === $b&lt;/td&gt; &lt;td&gt;Identity&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a and $b have the same key/value  pairs in the same order and of the same types.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a != $b&lt;/td&gt; &lt;td&gt;Inequality&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not equal to $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &lt;&gt; $b&lt;/td&gt; &lt;td&gt;Inequality&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not equal to $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a !== $b&lt;/td&gt; &lt;td&gt;Non-identity&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not identical to  $b.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;The &lt;var class=&quot;literal&quot;&gt;+&lt;/var&gt; operator appends the right handed array to the  left handed, whereas duplicated keys are NOT overwritten. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4587&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  array(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;apple&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;b&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;banana&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= array(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;pear&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;b&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;strawberry&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;c&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;cherry&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$c  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Union of $a and $b&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Union of \$a  and \$b: \n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$c&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$c  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Union of $b and $a&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Union of \$b  and \$a: \n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$c&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;When executed, this script will print the following:  &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;Union of $a and $b:&lt;br /&gt;array(3)  {&lt;br /&gt;  [&quot;a&quot;]=&gt;&lt;br /&gt;  string(5) &quot;apple&quot;&lt;br /&gt;  [&quot;b&quot;]=&gt;&lt;br /&gt;  string(6)  &quot;banana&quot;&lt;br /&gt;  [&quot;c&quot;]=&gt;&lt;br /&gt;  string(6) &quot;cherry&quot;&lt;br /&gt;}&lt;br /&gt;Union of $b and  $a:&lt;br /&gt;array(3) {&lt;br /&gt;  [&quot;a&quot;]=&gt;&lt;br /&gt;  string(4)  &quot;pear&quot;&lt;br /&gt;  [&quot;b&quot;]=&gt;&lt;br /&gt;  string(10)  &quot;strawberry&quot;&lt;br /&gt;  [&quot;c&quot;]=&gt;&lt;br /&gt;  string(6) &quot;cherry&quot;&lt;br /&gt;}&lt;/span&gt;  &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Elements of arrays are equal for the comparison if they have the same key and  value. &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN4592&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-5. Comparing arrays&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  array(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;apple&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;banana&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= array(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;banana&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;0&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt; &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;apple&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=== &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// bool(false)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;See also the manual sections on the Array  type and Array functions. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3936507931107136635/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/array-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3936507931107136635'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3936507931107136635'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/array-operators.html' title='Array Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-8602366802928270569</id><published>2009-01-08T17:28:00.001-08:00</published><updated>2009-01-08T17:28:23.870-08:00</updated><title type='text'>String Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.string&quot;&gt;String Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;There are two &lt;b class=&quot;type&quot;&gt;string&lt;/b&gt; operators. The first is the concatenation operator  (&#39;.&#39;), which returns the concatenation of its right and left arguments. The  second is the concatenating assignment operator (&#39;.=&#39;), which appends the  argument on the right side to the argument on the left side. Please read Assignment Operators for more  information. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4539&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Hello &quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;World!&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// now $b contains &quot;Hello  World!&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Hello  &quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;.= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;World!&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;     &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// now $a  contains &quot;Hello World!&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;See also the manual sections on the String type and String functions. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/8602366802928270569/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/string-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/8602366802928270569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/8602366802928270569'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/string-operators.html' title='String Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6001667007219014899</id><published>2009-01-08T17:27:00.004-08:00</published><updated>2009-01-08T17:28:00.908-08:00</updated><title type='text'>Logical Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.logical&quot;&gt;Logical Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4486&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-7. Logical Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;$a and $b&lt;/td&gt; &lt;td&gt;And&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if both $a and $b are &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a or $b&lt;/td&gt; &lt;td&gt;Or&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a xor $b&lt;/td&gt; &lt;td&gt;Xor&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, but not both.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;! $a&lt;/td&gt; &lt;td&gt;Not&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &amp;amp;&amp;amp; $b&lt;/td&gt; &lt;td&gt;And&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if both $a and $b are &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a || $b&lt;/td&gt; &lt;td&gt;Or&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;The reason for the two different variations of &quot;and&quot; and &quot;or&quot; operators is  that they operate at different precedences. (See Operator  Precedence.) &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6001667007219014899/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/logical-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6001667007219014899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6001667007219014899'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/logical-operators.html' title='Logical Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-876683670035609739</id><published>2009-01-08T17:27:00.003-08:00</published><updated>2009-01-08T17:27:38.192-08:00</updated><title type='text'>Incrementing/Decrementing Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.increment&quot;&gt;Incrementing/Decrementing  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP supports C-style pre- and post-increment and decrement operators. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The increment/decrement operators do not affect boolean values.  Decrementing &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; values has no effect too, but  incrementing them results in &lt;var class=&quot;literal&quot;&gt;1&lt;/var&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4449&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-6. Increment/decrement Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Effect&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;++$a&lt;/td&gt; &lt;td&gt;Pre-increment&lt;/td&gt; &lt;td&gt;Increments $a by one, then returns $a.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a++&lt;/td&gt; &lt;td&gt;Post-increment&lt;/td&gt; &lt;td&gt;Returns $a, then increments $a by one.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;--$a&lt;/td&gt; &lt;td&gt;Pre-decrement&lt;/td&gt; &lt;td&gt;Decrements $a by one, then returns $a.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a--&lt;/td&gt; &lt;td&gt;Post-decrement&lt;/td&gt; &lt;td&gt;Returns $a, then decrements $a by one.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;Here&#39;s a simple example script:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4475&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;h3&gt;Postincrement&lt;/h3&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  5: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++ . &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  6: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;h3&gt;Preincrement&lt;/h3&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  6: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. ++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  6: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;h3&gt;Postdecrement&lt;/h3&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  5: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;-- . &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  4: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;h3&gt;Predecrement&lt;/h3&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  4: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. --&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Should be  4: &quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;br /&gt;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;PHP follows Perl&#39;s convention when dealing with arithmetic operations on  character variables and not C&#39;s. For example, in Perl &#39;Z&#39;+1 turns into &#39;AA&#39;,  while in C &#39;Z&#39;+1 turns into &#39;[&#39; ( ord(&#39;Z&#39;) == 90, ord(&#39;[&#39;) == 91 ). Note that  character variables can be incremented but not decremented.  &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN4478&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-4. Arithmetic Operations on Character Variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$i &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;W&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;for (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$n&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$n&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&lt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$n&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++) {&lt;br /&gt;    echo  ++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$i &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;.  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;The above example will output:&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;screen&quot;&gt;X&lt;br /&gt;Y&lt;br /&gt;Z&lt;br /&gt;AA&lt;br /&gt;AB&lt;br /&gt;AC&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;Incrementing or decrementing booleans has no effect. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/876683670035609739/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/incrementingdecrementing-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/876683670035609739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/876683670035609739'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/incrementingdecrementing-operators.html' title='Incrementing/Decrementing Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-4516160520980654411</id><published>2009-01-08T17:27:00.001-08:00</published><updated>2009-01-08T17:27:16.589-08:00</updated><title type='text'>Execution Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.execution&quot;&gt;Execution  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP supports one execution operator: backticks (``). Note that these are not  single-quotes! PHP will attempt to execute the contents of the backticks as a  shell command; the output will be returned (i.e., it won&#39;t simply be dumped to  output; it can be assigned to a variable). Use of the backtick operator is  identical to &lt;b class=&quot;function&quot;&gt;shell_exec()&lt;/b&gt;.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4431&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$output &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  `&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;ls -al&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;`;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;&lt;pre&gt;$output&lt;/pre&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The backtick operator is disabled when safe mode is enabled or &lt;b class=&quot;function&quot;&gt;shell_exec()&lt;/b&gt; is  disabled. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;See also the manual section on Program Execution  functions, &lt;b class=&quot;function&quot;&gt;popen()&lt;/b&gt;  &lt;b class=&quot;function&quot;&gt;proc_open()&lt;/b&gt;, and Using PHP from the commandline.  &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/4516160520980654411/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/execution-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4516160520980654411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4516160520980654411'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/execution-operators.html' title='Execution Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-683991446186456522</id><published>2009-01-08T17:26:00.005-08:00</published><updated>2009-01-08T17:26:56.431-08:00</updated><title type='text'>Error Control Operators</title><content type='html'>&lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.errorcontrol&quot;&gt;Error Control  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP supports one error control operator: the at sign (@). When prepended to  an expression in PHP, any error messages that might be generated by that  expression will be ignored. &lt;/p&gt; &lt;p&gt;If the &lt;var class=&quot;option&quot;&gt;track_errors&lt;/var&gt; feature is enabled, any error message  generated by the expression will be saved in the variable $php_errormsg.  This variable will be overwritten on each error, so check early if you want to  use it. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4414&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/*  Intentional file error */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$my_file  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= @&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;file  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;non_existent_file&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)  or&lt;br /&gt;    die (&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Failed opening file: error  was &#39;$php_errormsg&#39;&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// this works for any expression, not just  functions:&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$value &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= @&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$cache&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// will not  issue a notice if the index $key doesn&#39;t exist.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The @-operator works only on expressions. A simple rule of thumb is: if  you can take the value of something, you can prepend the @ operator to it. For  instance, you can prepend it to variables, function and &lt;b class=&quot;function&quot;&gt;include()&lt;/b&gt; calls,  constants, and so forth. You cannot prepend it to function or class definitions,  or conditional structures such as &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; and &lt;var class=&quot;literal&quot;&gt;foreach&lt;/var&gt;, and so forth. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;See also &lt;b class=&quot;function&quot;&gt;error_reporting()&lt;/b&gt; and the manual section for Error Handling and Logging functions. &lt;/p&gt; &lt;div class=&quot;warning&quot;&gt;  &lt;table class=&quot;warning&quot; border=&quot;1&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align=&quot;middle&quot;&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align=&quot;left&quot;&gt; &lt;p&gt;Currently the &quot;@&quot; error-control operator prefix will even disable error  reporting for critical errors that will terminate script execution. Among other  things, this means that if you use &quot;@&quot; to suppress errors from a certain  function and either it isn&#39;t available or has been mistyped, the script will die  right there with no indication as to why. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/683991446186456522/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/error-control-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/683991446186456522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/683991446186456522'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/error-control-operators.html' title='Error Control Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5489823915121362029</id><published>2009-01-08T17:26:00.003-08:00</published><updated>2009-01-08T17:26:38.786-08:00</updated><title type='text'>Comparison Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.comparison&quot;&gt;Comparison  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Comparison operators, as their name implies, allow you to compare two values.  You may also be interested in viewing the type  comparison tables, as they show examples of various type related  comparisons. &lt;/p&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4260&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-4. Comparison Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;$a == $b&lt;/td&gt; &lt;td&gt;Equal&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is equal to $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a === $b&lt;/td&gt; &lt;td&gt;Identical&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is equal to $b, and they are of  the same type. (introduced in PHP 4) &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a != $b&lt;/td&gt; &lt;td&gt;Not equal&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not equal to $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &lt;&gt; $b&lt;/td&gt; &lt;td&gt;Not equal&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not equal to $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a !== $b&lt;/td&gt; &lt;td&gt;Not identical&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not equal to $b, or they are  not of the same type. (introduced in PHP 4) &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &lt; $b&lt;/td&gt; &lt;td&gt;Less than&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is strictly less than  $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &gt; $b&lt;/td&gt; &lt;td&gt;Greater than&lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is strictly greater than  $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &lt;= $b&lt;/td&gt; &lt;td&gt;Less than or equal to &lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is less than or equal to  $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &gt;= $b&lt;/td&gt; &lt;td&gt;Greater than or equal to &lt;/td&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is greater than or equal to  $b.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;If you compare an integer with a string, the string is converted to  a number. If you compare two numerical strings, they are compared as  integers. These rules also apply to the switch statement.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4317&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// 0 == 0 -&gt;  true&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;1&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;== &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;01&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// 1 == 1 -&gt;  true&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;switch (&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) {&lt;br /&gt;case  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;:&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;0&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    break;&lt;br /&gt;case &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// never reached because &quot;a&quot; is already matched with  0&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    break;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;If types of operands differ, comparison is done according to the following  table (in order). &lt;/p&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4320&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-5. Comparison with Different Types&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Type of Operand 1&lt;/th&gt; &lt;th&gt;Type of Operand 2&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;null&lt;/b&gt; or &lt;b class=&quot;type&quot;&gt;string&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;string&lt;/b&gt;&lt;/td&gt; &lt;td&gt;Convert &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; to &quot;&quot;, numerical or lexical  comparison&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;bool&lt;/b&gt; or &lt;b class=&quot;type&quot;&gt;null&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;Convert to &lt;b class=&quot;type&quot;&gt;bool&lt;/b&gt;,  &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; &lt; &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;object&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;object&lt;/b&gt;&lt;/td&gt; &lt;td&gt;Built-in classes can define its own comparison, different classes are  uncomparable, same class - compare properties the same way as arrays (PHP 4),  PHP 5 has its own explanation  &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;string&lt;/b&gt;, &lt;b class=&quot;type&quot;&gt;resource&lt;/b&gt; or &lt;b class=&quot;type&quot;&gt;number&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;string&lt;/b&gt;, &lt;b class=&quot;type&quot;&gt;resource&lt;/b&gt; or &lt;b class=&quot;type&quot;&gt;number&lt;/b&gt;&lt;/td&gt; &lt;td&gt;Translate strings and resources to numbers, usual math&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;array&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;array&lt;/b&gt;&lt;/td&gt; &lt;td&gt;Array with fewer members is smaller, if key from operand 1 is not found in  operand 2 then arrays are uncomparable, otherwise - compare value by value (see  following example)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;array&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;array&lt;/b&gt; is always  greater&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;object&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;type&quot;&gt;object&lt;/b&gt; is always  greater&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN4382&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-2. Transcription of standard array comparison&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Arrays  are compared like this with standard comparison operators&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;standard_array_compare&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;    if (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) &lt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)) {&lt;br /&gt;        return -&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $op1 &lt; $op2&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;} elseif (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) &gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)) {&lt;br /&gt;        return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $op1 &gt; $op2&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;}&lt;br /&gt;    foreach (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op1 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;as &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$key &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)  {&lt;br /&gt;        if (!&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;array_key_exists&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)) {&lt;br /&gt;            return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// uncomparable&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;} elseif (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$val  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&lt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;])  {&lt;br /&gt;            return -&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;        } elseif (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$val &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$op2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$key&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;]) {&lt;br /&gt;            return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $op1 == $op2&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;See also &lt;b class=&quot;function&quot;&gt;strcasecmp()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;strcmp()&lt;/b&gt;, Array  operators, and the manual section on Types. &lt;/p&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.operators.comparison.ternary&quot;&gt;Ternary  Operator&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Another conditional operator is the &quot;?:&quot; (or ternary) operator.  &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN4393&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-3. Assigning a default value&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Example usage for: Ternary Operator&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$action &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  (empty(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;])) ? &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;default&#39;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// The  above is identical to this if/else statement&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if (empty(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;]))  {&lt;br /&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$action &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;default&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;} else  {&lt;br /&gt;     &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$action &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;The  expression &lt;var class=&quot;literal&quot;&gt;(expr1) ? (expr2) : (expr3)&lt;/var&gt; evaluates to  &lt;var class=&quot;replaceable&quot;&gt;expr2&lt;/var&gt; if &lt;var class=&quot;replaceable&quot;&gt;expr1&lt;/var&gt;  evaluates to &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, and &lt;var class=&quot;replaceable&quot;&gt;expr3&lt;/var&gt; if &lt;var class=&quot;replaceable&quot;&gt;expr1&lt;/var&gt; evaluates to  &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Please note that the ternary operator is a statement, and that  it doesn&#39;t evaluate to a variable, but to the result of a statement. This is  important to know if you want to return a variable by reference. The statement  &lt;var class=&quot;literal&quot;&gt;return $var == 42 ? $a : $b;&lt;/var&gt; in a return-by-reference  function will therefore not work and a warning is issued in later PHP versions.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5489823915121362029/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/comparison-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5489823915121362029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5489823915121362029'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/comparison-operators.html' title='Comparison Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3741384787992313131</id><published>2009-01-08T17:26:00.001-08:00</published><updated>2009-01-08T17:26:18.952-08:00</updated><title type='text'>Bitwise Operators</title><content type='html'>&lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.bitwise&quot;&gt;Bitwise Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Bitwise operators allow you to turn specific bits within an integer on or  off. If both the left- and right-hand parameters are strings, the bitwise  operator will operate on the characters&#39; ASCII values. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4219&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;12 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;^  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Outputs &#39;5&#39;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;12&quot;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;^ &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;9&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Outputs the Backspace character (ascii  8)&lt;br /&gt;                 // (&#39;1&#39; (ascii 49)) ^ (&#39;9&#39; (ascii 57)) =  #8&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;hallo&quot; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;^  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Outputs the ascii values #0 #4 #0 #0  #0&lt;br /&gt;                        // &#39;a&#39; ^ &#39;e&#39; = #4&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4221&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-3. Bitwise Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;$a &amp;amp; $b&lt;/td&gt; &lt;td&gt;And&lt;/td&gt; &lt;td&gt;Bits that are set in both $a and $b are set.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a | $b&lt;/td&gt; &lt;td&gt;Or&lt;/td&gt; &lt;td&gt;Bits that are set in either $a or $b are set.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a ^ $b&lt;/td&gt; &lt;td&gt;Xor&lt;/td&gt; &lt;td&gt;Bits that are set in $a or $b but not both are set. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;~ $a&lt;/td&gt; &lt;td&gt;Not&lt;/td&gt; &lt;td&gt;Bits that are set in $a are not set, and vice versa. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &lt;&lt; $b&lt;/td&gt; &lt;td&gt;Shift left&lt;/td&gt; &lt;td&gt;Shift the bits of $a $b steps to the left (each step means &quot;multiply by  two&quot;) &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a &gt;&gt; $b&lt;/td&gt; &lt;td&gt;Shift right&lt;/td&gt; &lt;td&gt;Shift the bits of $a $b steps to the right (each step means &quot;divide by two&quot;)  &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class=&quot;warning&quot;&gt;  &lt;table class=&quot;warning&quot; border=&quot;1&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align=&quot;middle&quot;&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align=&quot;left&quot;&gt; &lt;p&gt;Don&#39;t right shift for more than 32 bits on 32 bits systems. Don&#39;t left shift  in case it results to number longer than 32 bits. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3741384787992313131/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/bitwise-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3741384787992313131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3741384787992313131'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/bitwise-operators.html' title='Bitwise Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6735968310423489214</id><published>2009-01-08T17:25:00.004-08:00</published><updated>2009-01-08T17:26:00.035-08:00</updated><title type='text'>Assignment Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.assignment&quot;&gt;Assignment  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The basic assignment operator is &quot;=&quot;. Your first inclination might be to  think of this as &quot;equal to&quot;. Don&#39;t. It really means that the left operand gets  set to the value of the expression on the rights (that is, &quot;gets set to&quot;). &lt;/p&gt; &lt;p&gt;The value of an assignment expression is the value assigned. That is, the  value of &quot;$a = 3&quot; is 3. This allows you to do some tricky things:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4206&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) +  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $a is equal to 9 now, and $b has been set  to 4.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;In addition to the basic assignment operator, there are &quot;combined operators&quot;  for all of the binary arithmetic and  string operators that allow you to use a value in an expression and then set its  value to the result of that expression. For example:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4210&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// sets $a to 8, as  if we had said: $a = $a + 5;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Hello  &quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;.= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;There!&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// sets $b to &quot;Hello There!&quot;, just like $b =  $b . &quot;There!&quot;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;Note that the assignment copies the original variable to the new one  (assignment by value), so changes to one will not affect the other. This may  also have relevance if you need to copy something like a large array inside a  tight loop. Since PHP 4, assignment by reference has been supported, using the  &lt;samp class=&quot;computeroutput&quot;&gt;$var = &amp;amp;$othervar;&lt;/samp&gt; syntax, but this is not  possible in PHP 3. &#39;Assignment by reference&#39; means that both variables end up  pointing at the same data, and nothing is copied anywhere. To learn more about  references, please read References  explained. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6735968310423489214/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/assignment-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6735968310423489214'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6735968310423489214'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/assignment-operators.html' title='Assignment Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5906118355695600408</id><published>2009-01-08T17:25:00.003-08:00</published><updated>2009-01-08T17:25:29.204-08:00</updated><title type='text'>Arithmetic Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.arithmetic&quot;&gt;Arithmetic  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Remember basic arithmetic from school? These work just like those. &lt;/p&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4162&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-2. Arithmetic Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;-$a&lt;/td&gt; &lt;td&gt;Negation&lt;/td&gt; &lt;td&gt;Opposite of $a.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a + $b&lt;/td&gt; &lt;td&gt;Addition&lt;/td&gt; &lt;td&gt;Sum of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a - $b&lt;/td&gt; &lt;td&gt;Subtraction&lt;/td&gt; &lt;td&gt;Difference of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a * $b&lt;/td&gt; &lt;td&gt;Multiplication&lt;/td&gt; &lt;td&gt;Product of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a / $b&lt;/td&gt; &lt;td&gt;Division&lt;/td&gt; &lt;td&gt;Quotient of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a % $b&lt;/td&gt; &lt;td&gt;Modulus&lt;/td&gt; &lt;td&gt;Remainder of $a divided by $b.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;The division operator (&quot;/&quot;) returns a float value anytime, even if the two  operands are integers (or strings that get converted to integers). &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Remainder &lt;var class=&quot;literal&quot;&gt;$a % $b&lt;/var&gt; is negative for  negative &lt;var class=&quot;literal&quot;&gt;$a&lt;/var&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;See also the manual page on Math functions.  &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5906118355695600408/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arithmetic-operators_08.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5906118355695600408'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5906118355695600408'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arithmetic-operators_08.html' title='Arithmetic Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6556953324794115987</id><published>2009-01-08T17:25:00.001-08:00</published><updated>2009-01-08T17:25:23.695-08:00</updated><title type='text'>Arithmetic Operators</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.arithmetic&quot;&gt;Arithmetic  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Remember basic arithmetic from school? These work just like those. &lt;/p&gt; &lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4162&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-2. Arithmetic Operators&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Example&lt;/th&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Result&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;-$a&lt;/td&gt; &lt;td&gt;Negation&lt;/td&gt; &lt;td&gt;Opposite of $a.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a + $b&lt;/td&gt; &lt;td&gt;Addition&lt;/td&gt; &lt;td&gt;Sum of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a - $b&lt;/td&gt; &lt;td&gt;Subtraction&lt;/td&gt; &lt;td&gt;Difference of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a * $b&lt;/td&gt; &lt;td&gt;Multiplication&lt;/td&gt; &lt;td&gt;Product of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a / $b&lt;/td&gt; &lt;td&gt;Division&lt;/td&gt; &lt;td&gt;Quotient of $a and $b.&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;$a % $b&lt;/td&gt; &lt;td&gt;Modulus&lt;/td&gt; &lt;td&gt;Remainder of $a divided by $b.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;The division operator (&quot;/&quot;) returns a float value anytime, even if the two  operands are integers (or strings that get converted to integers). &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Remainder &lt;var class=&quot;literal&quot;&gt;$a % $b&lt;/var&gt; is negative for  negative &lt;var class=&quot;literal&quot;&gt;$a&lt;/var&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;See also the manual page on Math functions.  &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6556953324794115987/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arithmetic-operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6556953324794115987'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6556953324794115987'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arithmetic-operators.html' title='Arithmetic Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5405898932048020305</id><published>2009-01-08T17:24:00.002-08:00</published><updated>2009-01-08T17:25:01.506-08:00</updated><title type='text'>Operators</title><content type='html'>&lt;h1&gt;&lt;a name=&quot;language.operators&quot;&gt;Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;TOC&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;Operator  Precedence &lt;/dt&gt;&lt;dt&gt;Arithmetic Operators &lt;/dt&gt;&lt;dt&gt;Assignment Operators &lt;/dt&gt;&lt;dt&gt;Bitwise Operators &lt;/dt&gt;&lt;dt&gt;Comparison Operators &lt;/dt&gt;&lt;dt&gt;Error Control Operators &lt;/dt&gt;&lt;dt&gt;Execution Operators &lt;/dt&gt;&lt;dt&gt;Incrementing/Decrementing  Operators &lt;/dt&gt;&lt;dt&gt;Logical Operators &lt;/dt&gt;&lt;dt&gt;String Operators &lt;/dt&gt;&lt;dt&gt;Array Operators &lt;/dt&gt;&lt;dt&gt;Type Operators&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt; &lt;p&gt;An operator is something that you feed with one or more values (or  expressions, in programming jargon) which yields another value (so that the  construction itself becomes an expression). So you can think of functions or  constructions that return a value (like print) as operators and those that  return nothing (like echo) as any other thing. &lt;/p&gt; &lt;p&gt;There are three types of operators. Firstly there is the unary operator which  operates on only one value, for example ! (the negation operator) or ++ (the  increment operator). The second group are termed binary operators; this group  contains most of the operators that PHP supports, and a list follows below in  the section Operator  Precedence. &lt;/p&gt; &lt;p&gt;The third group is the ternary operator: ?:. It should be used to select  between two expressions depending on a third one, rather than to select two  sentences or paths of execution. Surrounding ternary expressions with  parentheses is a very good idea. &lt;/p&gt; &lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.operators.precedence&quot;&gt;Operator  Precedence&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The precedence of an operator specifies how &quot;tightly&quot; it binds two  expressions together. For example, in the expression &lt;var class=&quot;literal&quot;&gt;1 + 5 *  3&lt;/var&gt;, the answer is &lt;var class=&quot;literal&quot;&gt;16&lt;/var&gt; and not &lt;var class=&quot;literal&quot;&gt;18&lt;/var&gt; because the multiplication (&quot;*&quot;) operator has a higher  precedence than the addition (&quot;+&quot;) operator. Parentheses may be used to force  precedence, if necessary. For instance: &lt;var class=&quot;literal&quot;&gt;(1 + 5) * 3&lt;/var&gt;  evaluates to &lt;var class=&quot;literal&quot;&gt;18&lt;/var&gt;. If operator precedence is equal, left  to right associativity is used. &lt;/p&gt; &lt;p&gt;The following table lists the precedence of operators with the  highest-precedence operators listed at the top of the table. Operators on the  same line have equal precedence, in which case their associativity decides which  order to evaluate them in.  &lt;/p&gt;&lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN4038&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-1. Operator Precedence&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Associativity&lt;/th&gt; &lt;th&gt;Operators&lt;/th&gt; &lt;th&gt;Additional Information&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;non-associative&lt;/td&gt; &lt;td&gt;new&lt;/td&gt; &lt;td&gt;new&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;right&lt;/td&gt; &lt;td&gt;[&lt;/td&gt; &lt;td&gt;&lt;b class=&quot;function&quot;&gt;array()&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;non-associative&lt;/td&gt; &lt;td&gt;++ --&lt;/td&gt; &lt;td&gt;increment/decrement  &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;non-associative&lt;/td&gt; &lt;td&gt;! ~ - (int) (float) (string) (array) (object) @&lt;/td&gt; &lt;td&gt;types &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;* / %&lt;/td&gt; &lt;td&gt;arithmetic &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;+ - .&lt;/td&gt; &lt;td&gt;arithmetic and string&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;&lt;&lt; &gt;&gt;&lt;/td&gt; &lt;td&gt;bitwise &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;non-associative&lt;/td&gt; &lt;td&gt;&lt; &lt;= &gt; &gt;=&lt;/td&gt; &lt;td&gt;comparison &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;non-associative&lt;/td&gt; &lt;td&gt;== != === !==&lt;/td&gt; &lt;td&gt;comparison &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;&amp;amp;&lt;/td&gt; &lt;td&gt;bitwise and references&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;^&lt;/td&gt; &lt;td&gt;bitwise &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;|&lt;/td&gt; &lt;td&gt;bitwise &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;&amp;amp;&amp;amp;&lt;/td&gt; &lt;td&gt;logical &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;||&lt;/td&gt; &lt;td&gt;logical &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;? :&lt;/td&gt; &lt;td&gt;ternary  &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;right&lt;/td&gt; &lt;td&gt;= += -= *= /= .= %= &amp;amp;= |= ^= &lt;&lt;= &gt;&gt;= &lt;/td&gt; &lt;td&gt;assignment &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;and&lt;/td&gt; &lt;td&gt;logical &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;xor&lt;/td&gt; &lt;td&gt;logical &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;or&lt;/td&gt; &lt;td&gt;logical &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;left&lt;/td&gt; &lt;td&gt;,&lt;/td&gt; &lt;td&gt;many uses&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;  &lt;p&gt;Left associativity means that the expression is evaluated from left to right,  right associativity means the opposite.  &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN4149&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-1. Associativity&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;*  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;%  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// (3 * 3) % 5 = 4&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;true &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;true &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;? &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// (true ? 0 : true) ? 1 : 2 = 2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $a = ($b += 3) -&gt; $a = 5, $b = 5&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Use  parentheses to increase readability of the code. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Although &lt;var class=&quot;literal&quot;&gt;!&lt;/var&gt; has a higher precedence than  &lt;var class=&quot;literal&quot;&gt;=&lt;/var&gt;, PHP will still allow expressions similar to the  following: &lt;var class=&quot;literal&quot;&gt;if (!$a = foo())&lt;/var&gt;, in which case the output  from &lt;var class=&quot;literal&quot;&gt;foo()&lt;/var&gt; is put into &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt;.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5405898932048020305/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/operators.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5405898932048020305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5405898932048020305'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/operators.html' title='Operators'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5414420009073859528</id><published>2009-01-08T17:24:00.001-08:00</published><updated>2009-01-08T17:24:38.674-08:00</updated><title type='text'>Expressions</title><content type='html'>&lt;h1&gt;&lt;a name=&quot;language.expressions&quot;&gt;Expressions&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Expressions are the most important building stones of PHP. In PHP, almost  anything you write is an expression. The simplest yet most accurate way to  define an expression is &quot;anything that has a value&quot;. &lt;/p&gt; &lt;p&gt;The most basic forms of expressions are constants and variables. When you  type &quot;$a = 5&quot;, you&#39;re assigning &#39;5&#39; into $a. &#39;5&#39;, obviously, has the value 5, or  in other words &#39;5&#39; is an expression with the value of 5 (in this case, &#39;5&#39; is an  integer constant). &lt;/p&gt; &lt;p&gt;After this assignment, you&#39;d expect $a&#39;s value to be 5 as well, so if you  wrote $b = $a, you&#39;d expect it to behave just as if you wrote $b = 5. In other  words, $a is an expression with the value of 5 as well. If everything works  right, this is exactly what will happen. &lt;/p&gt; &lt;p&gt;Slightly more complex examples for expressions are functions. For instance,  consider the following function:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3984&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;Assuming you&#39;re familiar with the concept of functions (if you&#39;re not, take a  look at the chapter about functions),  you&#39;d assume that typing &lt;var class=&quot;literal&quot;&gt;$c = foo()&lt;/var&gt; is essentially just  like writing &lt;var class=&quot;literal&quot;&gt;$c = 5&lt;/var&gt;, and you&#39;re right. Functions are  expressions with the value of their return value. Since foo() returns 5, the  value of the expression &#39;foo()&#39; is 5. Usually functions don&#39;t just return a  static value but compute something. &lt;/p&gt; &lt;p&gt;Of course, values in PHP don&#39;t have to be integers, and very often they  aren&#39;t. PHP supports four scalar value types: &lt;b class=&quot;type&quot;&gt;integer&lt;/b&gt; values,  floating point values (&lt;b class=&quot;type&quot;&gt;float&lt;/b&gt;), &lt;b class=&quot;type&quot;&gt;string&lt;/b&gt; values and &lt;b class=&quot;type&quot;&gt;boolean&lt;/b&gt; values (scalar values are values that you can&#39;t  &#39;break&#39; into smaller pieces, unlike arrays, for instance). PHP also supports two  composite (non-scalar) types: arrays and objects. Each of these value types can  be assigned into variables or returned from functions. &lt;/p&gt; &lt;p&gt;PHP takes expressions much further, in the same way many other languages do.  PHP is an expression-oriented language, in the sense that almost everything is  an expression. Consider the example we&#39;ve already dealt with, &#39;$a = 5&#39;. It&#39;s  easy to see that there are two values involved here, the value of the integer  constant &#39;5&#39;, and the value of $a which is being updated to 5 as well. But the  truth is that there&#39;s one additional value involved here, and that&#39;s the value  of the assignment itself. The assignment itself evaluates to the assigned value,  in this case 5. In practice, it means that &#39;$a = 5&#39;, regardless of what it does,  is an expression with the value 5. Thus, writing something like &#39;$b = ($a = 5)&#39;  is like writing &#39;$a = 5; $b = 5;&#39; (a semicolon marks the end of a statement).  Since assignments are parsed in a right to left order, you can also write &#39;$b =  $a = 5&#39;. &lt;/p&gt; &lt;p&gt;Another good example of expression orientation is pre- and post-increment and  decrement. Users of PHP and many other languages may be familiar with the  notation of variable++ and variable--. These are increment and decrement operators.  In PHP/FI 2, the statement &#39;$a++&#39; has no value (is not an expression), and thus  you can&#39;t assign it or use it in any way. PHP enhances the increment/decrement  capabilities by making these expressions as well, like in C. In PHP, like in C,  there are two types of increment - pre-increment and post-increment. Both  pre-increment and post-increment essentially increment the variable, and the  effect on the variable is identical. The difference is with the value of the  increment expression. Pre-increment, which is written &#39;++$variable&#39;, evaluates  to the incremented value (PHP increments the variable before reading its value,  thus the name &#39;pre-increment&#39;). Post-increment, which is written &#39;$variable++&#39;  evaluates to the original value of $variable, before it was incremented (PHP  increments the variable after reading its value, thus the name  &#39;post-increment&#39;). &lt;/p&gt; &lt;p&gt;A very common type of expressions are comparison expressions. These  expressions evaluate to either &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;. PHP supports &gt; (bigger than), &gt;= (bigger  than or equal to), == (equal), != (not equal), &lt; (smaller than) and &lt;=  (smaller than or equal to). The language also supports a set of strict  equivalence operators: === (equal to and same type) and !== (not equal to or not  same type). These expressions are most commonly used inside conditional  execution, such as &lt;var class=&quot;literal&quot;&gt;if&lt;/var&gt; statements. &lt;/p&gt; &lt;p&gt;The last example of expressions we&#39;ll deal with here is combined  operator-assignment expressions. You already know that if you want to increment  $a by 1, you can simply write &#39;$a++&#39; or &#39;++$a&#39;. But what if you want to add more  than one to it, for instance 3? You could write &#39;$a++&#39; multiple times, but this  is obviously not a very efficient or comfortable way. A much more common  practice is to write &#39;$a = $a + 3&#39;. &#39;$a + 3&#39; evaluates to the value of $a plus  3, and is assigned back into $a, which results in incrementing $a by 3. In PHP,  as in several other languages like C, you can write this in a shorter way, which  with time would become clearer and quicker to understand as well. Adding 3 to  the current value of $a can be written &#39;$a += 3&#39;. This means exactly &quot;take the  value of $a, add 3 to it, and assign it back into $a&quot;. In addition to being  shorter and clearer, this also results in faster execution. The value of &#39;$a +=  3&#39;, like the value of a regular assignment, is the assigned value. Notice that  it is NOT 3, but the combined value of $a plus 3 (this is the value that&#39;s  assigned into $a). Any two-place operator can be used in this  operator-assignment mode, for example &#39;$a -= 5&#39; (subtract 5 from the value of  $a), &#39;$b *= 7&#39; (multiply the value of $b by 7), etc. &lt;/p&gt; &lt;p&gt;There is one more expression that may seem odd if you haven&#39;t seen it in  other languages, the ternary conditional operator: &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4006&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$first &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;?  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$second &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$third&lt;br /&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;If the value of the first subexpression is &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; (non-zero), then the second subexpression is  evaluated, and that is the result of the conditional expression. Otherwise, the  third subexpression is evaluated, and that is the value. &lt;/p&gt; &lt;p&gt;The following example should help you understand pre- and post-increment and  expressions in general a bit better: &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN4012&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;double&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)&lt;br /&gt;{&lt;br /&gt;    return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$i&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;        &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* assign  the value five into the variable $a and $b */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$c &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;          &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/*  post-increment, assign original value of $a&lt;br /&gt;                       (5) to $c  */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$e &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$d &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= ++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;     &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/*  pre-increment, assign the incremented value of&lt;br /&gt;                       $b (6)  to $d and $e */&lt;br /&gt;&lt;br /&gt;/* at this point, both $d and $e are equal to 6  */&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$f &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;double&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$d&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++);  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* assign twice  the value of $d before&lt;br /&gt;                       the increment, 2*6 = 12 to $f  */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$g &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;double&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(++&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$e&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* assign twice  the value of $e after&lt;br /&gt;                       the increment, 2*7 = 14 to $g  */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$h &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$g &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;      &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* first, $g  is incremented by 10 and ends with the&lt;br /&gt;                       value of 24.  the value of the assignment (24) is&lt;br /&gt;                       then assigned  into $h, and $h ends with the value&lt;br /&gt;                       of 24 as well.  */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;Some expressions can be considered as statements. In this case, a statement  has the form of &#39;expr&#39; &#39;;&#39; that is, an expression followed by a semicolon. In  &#39;$b=$a=5;&#39;, $a=5 is a valid expression, but it&#39;s not a statement by itself.  &#39;$b=$a=5;&#39; however is a valid statement. &lt;/p&gt; &lt;p&gt;One last thing worth mentioning is the truth value of expressions. In many  events, mainly in conditional execution and loops, you&#39;re not interested in the  specific value of the expression, but only care about whether it means &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. The  constants &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; and &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; (case-insensitive) are the two possible boolean  values. When necessary, an expression is automatically converted to boolean. See  the section  about type-casting for details about how. &lt;/p&gt; &lt;p&gt;PHP provides a full and powerful implementation of expressions, and  documenting it entirely goes beyond the scope of this manual. The above examples  should give you a good idea about what expressions are and how you can construct  useful expressions. Throughout the rest of this manual we&#39;ll write &lt;var class=&quot;varname&quot;&gt;expr&lt;/var&gt; to indicate any valid PHP expression. &lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5414420009073859528/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/expressions.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5414420009073859528'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5414420009073859528'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/expressions.html' title='Expressions'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5550808073468777314</id><published>2009-01-08T17:23:00.002-08:00</published><updated>2009-01-08T17:24:13.846-08:00</updated><title type='text'>Magic constants</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.constants.predefined&quot;&gt;Magic constants&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP provides a large number of predefined  constants to any script which it runs. Many of these constants, however, are  created by various extensions, and will only be present when those extensions  are available, either via dynamic loading or because they have been compiled in.  &lt;/p&gt; &lt;p&gt;There are five magical constants that change depending on where they are  used. For example, the value of &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__LINE__&lt;/b&gt;&lt;/tt&gt; depends  on the line that it&#39;s used on in your script. These special constants are  case-insensitive and are as follows: &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;table&quot;&gt;&lt;a name=&quot;AEN3944&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 13-1. A few &quot;magical&quot; PHP constants&lt;/b&gt;&lt;/p&gt; &lt;table class=&quot;CALSTABLE&quot; border=&quot;1&quot;&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__LINE__&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt; &lt;td&gt;The current line number of the file. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__FILE__&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt; &lt;td&gt;The full path and filename of the file. If used inside an include, the name  of the included file is returned. Since PHP 4.0.2, &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__FILE__&lt;/b&gt;&lt;/tt&gt; always contains an absolute path whereas in  older versions it contained relative path under some circumstances. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__FUNCTION__&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt; &lt;td&gt;The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns  the function name as it was declared (case-sensitive). In PHP 4 its value is  always lowercased. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__CLASS__&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt; &lt;td&gt;The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the  class name as it was declared (case-sensitive). In PHP 4 its value is always  lowercased. &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;__METHOD__&lt;/b&gt;&lt;/tt&gt;&lt;/td&gt; &lt;td&gt;The class method name. (Added in PHP 5.0.0) The method name is returned as  it was declared (case-sensitive). &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;  &lt;p&gt;See also &lt;b class=&quot;function&quot;&gt;get_class()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;get_object_vars()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;file_exists()&lt;/b&gt; and &lt;b class=&quot;function&quot;&gt;function_exists()&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5550808073468777314/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/magic-constants.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5550808073468777314'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5550808073468777314'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/magic-constants.html' title='Magic constants'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3486602157801324068</id><published>2009-01-08T17:23:00.001-08:00</published><updated>2009-01-08T17:23:43.852-08:00</updated><title type='text'>Constants</title><content type='html'>&lt;h1&gt;&lt;a name=&quot;language.constants&quot;&gt;Constants&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;TOC&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;Syntax &lt;/dt&gt;&lt;dt&gt;Magic  constants&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt; &lt;p&gt;A constant is an identifier (name) for a simple value. As the name suggests,  that value cannot change during the execution of the script (except for magic constants, which aren&#39;t  actually constants). A constant is case-sensitive by default. By convention,  constant identifiers are always uppercase. &lt;/p&gt; &lt;p&gt;The name of a constant follows the same rules as any label in PHP. A valid  constant name starts with a letter or underscore, followed by any number of  letters, numbers, or underscores. As a regular expression, it would be expressed  thusly: &lt;var class=&quot;literal&quot;&gt;[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*&lt;/var&gt; &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3886&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 13-1. Valid and invalid constant names&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Valid constant names&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;FOO&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,     &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;something&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;FOO2&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,    &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;something  else&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;FOO_BAR&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;something more&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Invalid  constant names&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;2FOO&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,    &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;something&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// This is  valid, but should be avoided:&lt;br /&gt;// PHP may one day provide a magical  constant&lt;br /&gt;// that will break your script&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;__FOO__&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;something&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;For our purposes here, a letter is a-z, A-Z, and the ASCII  characters from 127 through 255 (0x7f-0xff). &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;Like superglobals, the scope  of a constant is global. You can access constants anywhere in your script  without regard to scope. For more information on scope, read the manual section  on variable scope. &lt;/p&gt; &lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.constants.syntax&quot;&gt;Syntax&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;You can define a constant by using the &lt;b class=&quot;function&quot;&gt;define()&lt;/b&gt;-function. Once a constant is defined, it can  never be changed or undefined. &lt;/p&gt; &lt;p&gt;Only scalar data (&lt;b class=&quot;type&quot;&gt;boolean&lt;/b&gt;, &lt;b class=&quot;type&quot;&gt;integer&lt;/b&gt;, &lt;b class=&quot;type&quot;&gt;float&lt;/b&gt; and &lt;b class=&quot;type&quot;&gt;string&lt;/b&gt;) can be contained in constants. &lt;/p&gt; &lt;p&gt;You can get the value of a constant by simply specifying its name. Unlike  with variables, you should &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;not&lt;/i&gt;&lt;/span&gt;  prepend a constant with a &lt;var class=&quot;literal&quot;&gt;$&lt;/var&gt;. You can also use the  function &lt;b class=&quot;function&quot;&gt;constant()&lt;/b&gt;  to read a constant&#39;s value if you wish to obtain the constant&#39;s name  dynamically. Use &lt;b class=&quot;function&quot;&gt;get_defined_constants()&lt;/b&gt; to get a list of all defined  constants. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Constants and (global) variables are in a different namespace.  This implies that for example &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; and &lt;var class=&quot;varname&quot;&gt;$TRUE&lt;/var&gt; are generally different. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;If you use an undefined constant, PHP assumes that you mean the name of the  constant itself, just as if you called it as a &lt;b class=&quot;type&quot;&gt;string&lt;/b&gt; (CONSTANT vs  &quot;CONSTANT&quot;). An error of level E_NOTICE will be  issued when this happens. See also the manual entry on why $foo[bar] is  wrong (unless you first &lt;b class=&quot;function&quot;&gt;define()&lt;/b&gt; &lt;var class=&quot;literal&quot;&gt;bar&lt;/var&gt; as a constant). If  you simply want to check if a constant is set, use the &lt;b class=&quot;function&quot;&gt;defined()&lt;/b&gt; function. &lt;/p&gt; &lt;p&gt;These are the differences between constants and variables:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;Constants do not have a dollar sign (&lt;var class=&quot;literal&quot;&gt;$&lt;/var&gt;) before them;  &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Constants may only be defined using the &lt;b class=&quot;function&quot;&gt;define()&lt;/b&gt; function, not by simple assignment; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Constants may be defined and accessed anywhere without regard to variable  scoping rules; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Constants may not be redefined or undefined once they have been set; and &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Constants may only evaluate to scalar values. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3934&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 13-2. Defining Constants&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;define&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;CONSTANT&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Hello world.&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;CONSTANT&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// outputs &quot;Hello world.&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Constant&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// outputs &quot;Constant&quot; and issues a  notice.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3486602157801324068/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/constants.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3486602157801324068'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3486602157801324068'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/constants.html' title='Constants'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6586813664214396094</id><published>2009-01-08T17:22:00.004-08:00</published><updated>2009-01-08T17:23:22.007-08:00</updated><title type='text'>Variables from outside PHP</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.variables.external&quot;&gt;Variables from outside  PHP&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.external.form&quot;&gt;HTML Forms (GET and  POST)&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;When a form is submitted to a PHP script, the information from that form is  automatically made available to the script. There are many ways to access this  information, for example: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3801&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-8. A simple HTML form&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;html&quot;&gt;&lt;form action=&quot;foo.php&quot; method=&quot;post&quot;&gt;&lt;br /&gt;   Name:  &lt;input type=&quot;text&quot; name=&quot;username&quot;&gt;&lt;br /&gt;&lt;br /&gt;   Email: &lt;input type=&quot;text&quot; name=&quot;email&quot;&gt;&lt;br /&gt;&lt;br /&gt;   &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Submit me!&quot;&gt;&lt;br /&gt;&lt;/form&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;Depending on your particular setup and personal preferences, there are many  ways to access data from your HTML forms. Some examples are: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3806&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-9. Accessing data from a simple POST HTML form&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;html&quot;&gt;&lt;?php&lt;br /&gt;// Available since PHP 4.1.0&lt;br /&gt;&lt;br /&gt;  echo $_POST[&#39;username&#39;];&lt;br /&gt;  echo $_REQUEST[&#39;username&#39;];&lt;br /&gt;&lt;br /&gt;  import_request_variables(&#39;p&#39;, &#39;p_&#39;);&lt;br /&gt;  echo $p_username;&lt;br /&gt;&lt;br /&gt;// Available since PHP 3. As of PHP 5.0.0, these long predefined&lt;br /&gt;// variables can be disabled with the register_long_arrays directive.&lt;br /&gt;&lt;br /&gt;  echo $HTTP_POST_VARS[&#39;username&#39;];&lt;br /&gt;&lt;br /&gt;// Available if the PHP directive register_globals = on. As of&lt;br /&gt;// PHP 4.2.0 the default value of register_globals = off.&lt;br /&gt;// Using/relying on this method is not preferred.&lt;br /&gt;&lt;br /&gt;  echo $username;&lt;br /&gt;?&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;Using a GET form is similar except you&#39;ll use the appropriate GET predefined  variable instead. GET also applies to the QUERY_STRING (the information after  the &#39;?&#39; in a URL). So, for example, &lt;var class=&quot;literal&quot;&gt;http://www.example.com/test.php?id=3&lt;/var&gt; contains GET data which  is accessible with &lt;var class=&quot;varname&quot;&gt;$_GET[&#39;id&#39;]&lt;/var&gt;. See also $_REQUEST and &lt;b class=&quot;function&quot;&gt;import_request_variables()&lt;/b&gt;. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Superglobal  arrays, like &lt;var class=&quot;varname&quot;&gt;$_POST&lt;/var&gt; and &lt;var class=&quot;varname&quot;&gt;$_GET&lt;/var&gt;, became available in PHP 4.1.0 &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;As shown, before PHP 4.2.0 the default value for register_globals was &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;on&lt;/i&gt;&lt;/span&gt;. And, in PHP 3 it was always on.  The PHP community is encouraging all to not rely on this directive as it&#39;s  preferred to assume it&#39;s &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;off&lt;/i&gt;&lt;/span&gt;  and code accordingly. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The magic_quotes_gpc configuration  directive affects Get, Post and Cookie values. If turned on, value (It&#39;s &quot;PHP!&quot;)  will automagically become (It\&#39;s \&quot;PHP!\&quot;). Escaping is needed for DB insertion.  See also &lt;b class=&quot;function&quot;&gt;addslashes()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;stripslashes()&lt;/b&gt; and magic_quotes_sybase.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;PHP also understands arrays in the context of form variables (see the related faq). You may, for example, group related  variables together, or use this feature to retrieve values from a multiple  select input. For example, let&#39;s post a form to itself and upon submission  display the data: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3832&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-10. More complex form variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if  (isset(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;]) &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;action&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;] ==  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;submitted&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;&lt;pre&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;print_r&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;&lt;a href=&quot;&quot;&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;PHP_SELF&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;]  .&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;&quot;&gt;Please try  again&lt;/a&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;&lt;/pre&gt;&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;} else {&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;form action=&quot;&lt;span style=&quot;&gt;&lt;?php &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_SERVER&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;PHP_SELF&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;&quot;  method=&quot;post&quot;&gt;&lt;br /&gt;    Name:  &lt;input type=&quot;text&quot; name=&quot;personal[name]&quot;&gt;&lt;br /&gt;&lt;br /&gt;    Email: &lt;input type=&quot;text&quot; name=&quot;personal[email]&quot;&gt;&lt;br /&gt;&lt;br /&gt;    Beer: &lt;br /&gt;&lt;br /&gt;    &lt;select name=&quot;beer[]&quot;&gt;&lt;br /&gt;        &lt;option value=&quot;warthog&quot;&gt;Warthog&lt;/option&gt;&lt;br /&gt;        &lt;option value=&quot;guinness&quot;&gt;Guinness&lt;/option&gt;&lt;br /&gt;        &lt;option value=&quot;stuttgarter&quot;&gt;Stuttgarter  Schwabenbräu&lt;/option&gt;&lt;br /&gt;    &lt;/select&gt;&lt;br /&gt;&lt;br /&gt;    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;submitted&quot;&gt;&lt;br /&gt;    &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit me!&quot;&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;In PHP 3, the array form variable usage is limited to single-dimensional  arrays. As of PHP 4, no such restriction applies. &lt;/p&gt; &lt;div class=&quot;sect3&quot;&gt; &lt;h3 class=&quot;sect3&quot;&gt;&lt;a name=&quot;language.variables.external.form.submit&quot;&gt;IMAGE SUBMIT  variable names&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;When submitting a form, it is possible to use an image instead of the  standard submit button with a tag like: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3839&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;html&quot;&gt;&lt;input type=&quot;image&quot; src=&quot;image.gif&quot; name=&quot;sub&quot;&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;When the user clicks somewhere on the image, the accompanying form will be  transmitted to the server with two additional variables, sub_x and sub_y. These  contain the coordinates of the user click within the image. The experienced may  note that the actual variable names sent by the browser contains a period rather  than an underscore, but PHP converts the period to an underscore automatically.  &lt;/p&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.external.cookies&quot;&gt;HTTP  Cookies&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;PHP transparently supports HTTP cookies as defined by Netscape&#39;s Spec. Cookies are a mechanism for storing data in the  remote browser and thus tracking or identifying return users. You can set  cookies using the &lt;b class=&quot;function&quot;&gt;setcookie()&lt;/b&gt; function. Cookies are part of the HTTP  header, so the SetCookie function must be called before any output is sent to  the browser. This is the same restriction as for the &lt;b class=&quot;function&quot;&gt;header()&lt;/b&gt; function. Cookie  data is then available in the appropriate cookie data arrays, such as &lt;var class=&quot;varname&quot;&gt;$_COOKIE&lt;/var&gt;, &lt;var class=&quot;varname&quot;&gt;$HTTP_COOKIE_VARS&lt;/var&gt; as well  as in &lt;var class=&quot;varname&quot;&gt;$_REQUEST&lt;/var&gt;. See the &lt;b class=&quot;function&quot;&gt;setcookie()&lt;/b&gt; manual page  for more details and examples. &lt;/p&gt; &lt;p&gt;If you wish to assign multiple values to a single cookie variable, you may  assign it as an array. For example: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3853&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;  setcookie&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;MyCookie[foo]&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Testing 1&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;setcookie&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;MyCookie[bar]&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Testing 2&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;That will create two separate cookies although MyCookie will now be a single  array in your script. If you want to set just one cookie with multiple values,  consider using &lt;b class=&quot;function&quot;&gt;serialize()&lt;/b&gt; or &lt;b class=&quot;function&quot;&gt;explode()&lt;/b&gt; on the value first. &lt;/p&gt; &lt;p&gt;Note that a cookie will replace a previous cookie by the same name in your  browser unless the path or domain is different. So, for a shopping cart  application you may want to keep a counter and pass this along. i.e. &lt;/p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3859&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-11. A &lt;b class=&quot;function&quot;&gt;setcookie()&lt;/b&gt; example&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if  (isset(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_COOKIE&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;count&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_COOKIE&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;count&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;] +  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}  else {&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;setcookie&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;count&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;setcookie&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;Cart[$count]&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$item&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;time&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;3600&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.external.dot-in-names&quot;&gt;Dots in  incoming variable names&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Typically, PHP does not alter the names of variables when they are passed  into a script. However, it should be noted that the dot (period, full stop) is  not a valid character in a PHP variable name. For the reason, look at it:  &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$varname&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;ext&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* invalid  variable name */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Now, what the parser sees is a variable  named &lt;var class=&quot;varname&quot;&gt;$varname&lt;/var&gt;, followed by the string concatenation  operator, followed by the barestring (i.e. unquoted string which doesn&#39;t match  any known key or reserved words) &#39;ext&#39;. Obviously, this doesn&#39;t have the  intended result. &lt;/p&gt; &lt;p&gt;For this reason, it is important to note that PHP will automatically replace  any dots in incoming variable names with underscores. &lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.determining-type-of&quot;&gt;Determining  variable types&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Because PHP determines the types of variables and converts them (generally)  as needed, it is not always obvious what type a given variable is at any one  time. PHP includes several functions which find out what type a variable is,  such as: &lt;b class=&quot;function&quot;&gt;gettype()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;is_array()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;is_float()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;is_int()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;is_object()&lt;/b&gt;, and &lt;b class=&quot;function&quot;&gt;is_string()&lt;/b&gt;. See also  the chapter on Types. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6586813664214396094/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variables-from-outside-php.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6586813664214396094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6586813664214396094'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variables-from-outside-php.html' title='Variables from outside PHP'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-4140925421156478054</id><published>2009-01-08T17:22:00.003-08:00</published><updated>2009-01-08T17:22:46.385-08:00</updated><title type='text'>Variable variables</title><content type='html'>&lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.variables.variable&quot;&gt;Variable variables&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Sometimes it is convenient to be able to have variable variable names. That  is, a variable name which can be set and used dynamically. A normal variable is  set with a statement such as: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3770&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;hello&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;A variable variable takes the value of a variable and treats that as the name  of a variable. In the above example, &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;hello&lt;/i&gt;&lt;/span&gt;, can be used as the name of a variable by using  two dollar signs. i.e. &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3774&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;world&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;At this point two variables have been defined and stored in the PHP symbol  tree: &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; with contents &quot;hello&quot; and &lt;var class=&quot;varname&quot;&gt;$hello&lt;/var&gt; with contents &quot;world&quot;. Therefore, this statement:  &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3779&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;$a ${$a}&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;produces the exact same output as: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3782&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;$a $hello&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;i.e. they both produce: &lt;samp class=&quot;computeroutput&quot;&gt;hello world&lt;/samp&gt;. &lt;/p&gt; &lt;p&gt;In order to use variable variables with arrays, you have to resolve an  ambiguity problem. That is, if you write &lt;var class=&quot;varname&quot;&gt;$$a[1]&lt;/var&gt; then  the parser needs to know if you meant to use &lt;var class=&quot;varname&quot;&gt;$a[1]&lt;/var&gt; as a  variable, or if you wanted &lt;var class=&quot;varname&quot;&gt;$$a&lt;/var&gt; as the variable and then  the [1] index from that variable. The syntax for resolving this ambiguity is:  &lt;var class=&quot;varname&quot;&gt;${$a[1]}&lt;/var&gt; for the first case and &lt;var class=&quot;varname&quot;&gt;${$a}[1]&lt;/var&gt; for the second. &lt;/p&gt; &lt;div class=&quot;warning&quot;&gt;  &lt;table class=&quot;warning&quot; border=&quot;1&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align=&quot;middle&quot;&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align=&quot;left&quot;&gt; &lt;p&gt;Please note that variable variables cannot be used with PHP&#39;s Superglobal  arrays within functions or class methods. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/4140925421156478054/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variable-variables.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4140925421156478054'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4140925421156478054'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variable-variables.html' title='Variable variables'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3248372540714650094</id><published>2009-01-08T17:22:00.001-08:00</published><updated>2009-01-08T17:22:25.724-08:00</updated><title type='text'>Variable scope</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.variables.scope&quot;&gt;Variable scope&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The scope of a variable is the context within which it is defined. For the  most part all PHP variables only have a single scope. This single scope spans  included and required files as well. For example: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3680&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;include &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;b.inc&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;Here the &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; variable will be available within the  included &lt;tt class=&quot;filename&quot;&gt;b.inc&lt;/tt&gt; script. However, within user-defined  functions a local function scope is introduced. Any variable used inside a  function is by default limited to the local function scope. For example: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3685&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* global scope */&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{ &lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;/* reference to  local scope variable */&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;This script will not produce any output because the echo statement refers to  a local version of the &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; variable, and it has not been  assigned a value within this scope. You may notice that this is a little bit  different from the C language in that global variables in C are automatically  available to functions unless specifically overridden by a local definition.  This can cause some problems in that people may inadvertently change a global  variable. In PHP global variables must be declared global inside a function if  they are going to be used in that function. &lt;/p&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.scope.global&quot;&gt;The global  keyword&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;First, an example use of &lt;var class=&quot;literal&quot;&gt;global&lt;/var&gt;: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3694&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-1. Using global&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Sum&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    global &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Sum&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;The above script will output &quot;3&quot;. By declaring &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt;  and &lt;var class=&quot;varname&quot;&gt;$b&lt;/var&gt; global within the function, all references to  either variable will refer to the global version. There is no limit to the  number of global variables that can be manipulated by a function. &lt;/p&gt; &lt;p&gt;A second way to access variables from the global scope is to use the special  PHP-defined &lt;var class=&quot;varname&quot;&gt;$GLOBALS&lt;/var&gt; array. The previous example can be  rewritten as: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3703&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-2. Using &lt;var class=&quot;varname&quot;&gt;$GLOBALS&lt;/var&gt; instead of  global&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Sum&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$GLOBALS&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$GLOBALS&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;a&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;] + &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$GLOBALS&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;b&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Sum&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$b&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;The &lt;var class=&quot;varname&quot;&gt;$GLOBALS&lt;/var&gt; array is an associative array with the  name of the global variable being the key and the contents of that variable  being the value of the array element. Notice how &lt;var class=&quot;varname&quot;&gt;$GLOBALS&lt;/var&gt; exists in any scope, this is because $GLOBALS is a  superglobal.  Here&#39;s an example demonstrating the power of superglobals: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3712&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-3. Example demonstrating superglobals and scope&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test_global&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Most predefined variables aren&#39;t &quot;super&quot; and require&lt;br /&gt;    // &#39;global&#39; to be  available to the functions local scope.&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;global &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$HTTP_POST_VARS&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;   &lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$HTTP_POST_VARS&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;name&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;   &lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Superglobals are available in any scope and do&lt;br /&gt;    // not require &#39;global&#39;.  Superglobals are available&lt;br /&gt;    // as of PHP 4.1.0, and HTTP_POST_VARS is  now&lt;br /&gt;    // deemed deprecated.&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_POST&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;name&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;];&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.scope.static&quot;&gt;Using static  variables&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Another important feature of variable scoping is the &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;static&lt;/i&gt;&lt;/span&gt; variable. A static variable exists only in a  local function scope, but it does not lose its value when program execution  leaves this scope. Consider the following example: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3720&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-4. Example demonstrating need for static variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;This function is quite useless since every time it is called it sets &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; to &lt;var class=&quot;literal&quot;&gt;0&lt;/var&gt; and prints &quot;0&quot;. The &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt;++ which increments the variable serves no purpose since  as soon as the function exits the &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; variable  disappears. To make a useful counting function which will not lose track of the  current count, the &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; variable is declared static: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3730&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-5. Example use of static variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt;Now, every time the Test() function is called it will print the value of &lt;var class=&quot;varname&quot;&gt;$a&lt;/var&gt; and increment it. &lt;/p&gt; &lt;p&gt;Static variables also provide one way to deal with recursive functions. A  recursive function is one which calls itself. Care must be taken when writing a  recursive function because it is possible to make it recurse indefinitely. You  must make sure you have an adequate way of terminating the recursion. The  following simple function recursively counts to 10, using the static variable  &lt;var class=&quot;varname&quot;&gt;$count&lt;/var&gt; to know when to stop: &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3738&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-6. Static variables with recursive functions&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;    static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    if (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;&lt; &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)  {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;Test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$count&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;--;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Static variables may be declared as seen in the examples above.  Trying to assign values to these variables which are the result of expressions  will cause a parse error. &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3744&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-7. Declaring static variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(){&lt;br /&gt;    static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$int &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;          &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// correct &lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$int &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;        &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  wrong  (as it is an expression)&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$int  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;sqrt&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;121&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// wrong  (as it is an expression  too)&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$int&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.variables.scope.references&quot;&gt;References with  global and static variables&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;The Zend Engine 1, driving PHP 4, implements the static  and global  modifier for variables in terms of references. For example, a true global  variable imported inside a function scope with the &lt;var class=&quot;literal&quot;&gt;global&lt;/var&gt; statement actually creates a reference to the global  variable. This can lead to unexpected behaviour which the following example  addresses: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3754&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test_global_ref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;() {&lt;br /&gt;    global &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;new &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;stdclass&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test_global_noref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()  {&lt;br /&gt;    global &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= new &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;stdclass&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test_global_ref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test_global_noref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;Executing this example will result in the following output: &lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;screen&quot;&gt;NULL&lt;br /&gt;object(stdClass)(0) {&lt;br /&gt;}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;A similar behaviour applies to the &lt;var class=&quot;literal&quot;&gt;static&lt;/var&gt; statement.  References are not stored statically: &lt;/p&gt; &lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3760&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function  &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_ref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;() {&lt;br /&gt;    static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Static object: &#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;    if  (!isset(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)) {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Assign a reference to the static variable&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;new  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;stdclass&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;    return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_noref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()  {&lt;br /&gt;    static &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Static object: &#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;    if  (!isset(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;)) {&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Assign the object to the static variable&lt;br /&gt;        &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= new  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;stdclass&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;-&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;property&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;++;&lt;br /&gt;    return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj1  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_ref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$still_obj1  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_ref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;\n&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj2 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_noref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$still_obj2  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;get_instance_noref&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;p&gt;Executing this example will result in the following output: &lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class=&quot;screen&quot;&gt;Static object: NULL&lt;br /&gt;Static object: NULL&lt;br /&gt;&lt;br /&gt;Static object: NULL&lt;br /&gt;Static object: object(stdClass)(1) {&lt;br /&gt; [&quot;property&quot;]=&gt;&lt;br /&gt; int(1)&lt;br /&gt;}&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;This example demonstrates that when assigning a reference to a static  variable, it&#39;s not &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;remembered&lt;/i&gt;&lt;/span&gt;  when you call the &lt;var class=&quot;literal&quot;&gt;&amp;amp;get_instance_ref()&lt;/var&gt; function a  second time. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3248372540714650094/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variable-scope.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3248372540714650094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3248372540714650094'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variable-scope.html' title='Variable scope'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-7697917606089125284</id><published>2009-01-08T17:21:00.003-08:00</published><updated>2009-01-08T17:21:58.453-08:00</updated><title type='text'>Predefined variables</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.variables.predefined&quot;&gt;Predefined  variables&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP provides a large number of predefined variables to any script which it  runs. Many of these variables, however, cannot be fully documented as they are  dependent upon which server is running, the version and setup of the server, and  other factors. Some of these variables will not be available when PHP is run on  the command line. For a listing of these  variables, please see the section on Reserved  Predefined Variables. &lt;/p&gt; &lt;div class=&quot;warning&quot;&gt;  &lt;table class=&quot;warning&quot; border=&quot;1&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align=&quot;middle&quot;&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align=&quot;left&quot;&gt; &lt;p&gt;In PHP 4.2.0 and later, the default value for the PHP directive register_globals is &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;off&lt;/i&gt;&lt;/span&gt;. This is a major change in PHP.  Having register_globals &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;off&lt;/i&gt;&lt;/span&gt;  affects the set of predefined variables available in the global scope. For  example, to get &lt;var class=&quot;varname&quot;&gt;DOCUMENT_ROOT&lt;/var&gt; you&#39;ll use &lt;var class=&quot;varname&quot;&gt;$_SERVER[&#39;DOCUMENT_ROOT&#39;]&lt;/var&gt; instead of &lt;var class=&quot;varname&quot;&gt;$DOCUMENT_ROOT&lt;/var&gt;, or &lt;var class=&quot;varname&quot;&gt;$_GET[&#39;id&#39;]&lt;/var&gt; from  the URL &lt;var class=&quot;literal&quot;&gt;http://www.example.com/test.php?id=3&lt;/var&gt; instead of  &lt;var class=&quot;varname&quot;&gt;$id&lt;/var&gt;, or &lt;var class=&quot;varname&quot;&gt;$_ENV[&#39;HOME&#39;]&lt;/var&gt; instead  of &lt;var class=&quot;varname&quot;&gt;$HOME&lt;/var&gt;. &lt;/p&gt; &lt;p&gt;For related information on this change, read the configuration entry for register_globals, the security  chapter on Using Register Globals , as well  as the PHP 4.1.0  and 4.2.0  Release Announcements. &lt;/p&gt; &lt;p&gt;Using the available PHP Reserved Predefined Variables, like the superglobal  arrays, is preferred. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;From version 4.1.0 onward, PHP provides an additional set of predefined  arrays containing variables from the web server (if applicable), the  environment, and user input. These new arrays are rather special in that they  are automatically global--i.e., automatically available in every scope. For this  reason, they are often known as &#39;autoglobals&#39; or &#39;superglobals&#39;. (There is no  mechanism in PHP for user-defined superglobals.) The superglobals are listed  below; however, for a listing of their contents and further discussion on PHP  predefined variables and their natures, please see the section Reserved Predefined Variables. Also, you&#39;ll  notice how the older predefined variables (&lt;var class=&quot;varname&quot;&gt;$HTTP_*_VARS&lt;/var&gt;) still exist. As of PHP 5.0.0, the long PHP predefined variable arrays may be  disabled with the register_long_arrays  directive. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;Variable variables: &lt;/b&gt;Superglobals cannot be used as variable variables inside functions  or class methods. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Even though both the superglobal and HTTP_*_VARS can exist at  the same time; they are not identical, so modifying one will not change the  other. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;If certain variables in variables_order are not set, their  appropriate PHP predefined arrays are also left empty. &lt;/p&gt;  &lt;div class=&quot;variablelist&quot;&gt; &lt;p&gt;&lt;b&gt;PHP Superglobals&lt;/b&gt;&lt;/p&gt; &lt;dl&gt;&lt;dt&gt;$GLOBALS &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Contains a reference to every variable which is currently available within  the global scope of the script. The keys of this array are the names of the  global variables. &lt;var class=&quot;varname&quot;&gt;$GLOBALS&lt;/var&gt; has existed since PHP 3.  &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_SERVER &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables set by the web server or otherwise directly related to the  execution environment of the current script. Analogous to the old &lt;var class=&quot;varname&quot;&gt;$HTTP_SERVER_VARS&lt;/var&gt; array (which is still available, but  deprecated). &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_GET &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via URL query string. Analogous to the old  &lt;var class=&quot;varname&quot;&gt;$HTTP_GET_VARS&lt;/var&gt; array (which is still available, but  deprecated). &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_POST &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via HTTP POST. Analogous to the old &lt;var class=&quot;varname&quot;&gt;$HTTP_POST_VARS&lt;/var&gt; array (which is still available, but  deprecated). &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_COOKIE &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via HTTP cookies. Analogous to the old &lt;var class=&quot;varname&quot;&gt;$HTTP_COOKIE_VARS&lt;/var&gt; array (which is still available, but  deprecated). &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_FILES &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via HTTP post file uploads. Analogous to the  old &lt;var class=&quot;varname&quot;&gt;$HTTP_POST_FILES&lt;/var&gt; array (which is still available,  but deprecated). See POST method  uploads for more information. &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_ENV &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via the environment. Analogous to the old  &lt;var class=&quot;varname&quot;&gt;$HTTP_ENV_VARS&lt;/var&gt; array (which is still available, but  deprecated). &lt;/p&gt; &lt;/dd&gt;&lt;dt&gt;$_REQUEST &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables provided to the script via the GET, POST, and COOKIE input  mechanisms, and which therefore cannot be trusted. The presence and order of  variable inclusion in this array is defined according to the PHP variables_order configuration  directive. This array has no direct analogue in versions of PHP prior to 4.1.0.  See also &lt;b class=&quot;function&quot;&gt;import_request_variables()&lt;/b&gt;. &lt;/p&gt; &lt;div class=&quot;caution&quot;&gt;  &lt;table class=&quot;caution&quot; border=&quot;1&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align=&quot;middle&quot;&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align=&quot;left&quot;&gt; &lt;p&gt;Since PHP 4.3.0, FILE information from &lt;var class=&quot;varname&quot;&gt;$_FILES&lt;/var&gt; does  not exist in &lt;var class=&quot;varname&quot;&gt;$_REQUEST&lt;/var&gt;.  &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;When running on the command  line , this will &lt;span class=&quot;emphasis&quot;&gt;&lt;i class=&quot;emphasis&quot;&gt;not&lt;/i&gt;&lt;/span&gt;  include the &lt;var class=&quot;varname&quot;&gt;argv&lt;/var&gt; and &lt;var class=&quot;varname&quot;&gt;argc&lt;/var&gt;  entries; these are present in the &lt;var class=&quot;varname&quot;&gt;$_SERVER&lt;/var&gt; array.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;/dd&gt;&lt;dt&gt;$_SESSION &lt;/dt&gt;&lt;dd&gt; &lt;p&gt;Variables which are currently registered to a script&#39;s session. Analogous to  the old &lt;var class=&quot;varname&quot;&gt;$HTTP_SESSION_VARS&lt;/var&gt; array (which is still  available, but deprecated). See the Session handling  functions section for more information. &lt;/p&gt;&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/7697917606089125284/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/predefined-variables.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7697917606089125284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7697917606089125284'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/predefined-variables.html' title='Predefined variables'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-4741657912932838980</id><published>2009-01-08T17:21:00.001-08:00</published><updated>2009-01-08T17:21:33.956-08:00</updated><title type='text'>Variables</title><content type='html'>&lt;h1&gt;&lt;a name=&quot;language.variables&quot;&gt;Variables&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;TOC&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;Basics &lt;/dt&gt;&lt;dt&gt;Predefined variables &lt;/dt&gt;&lt;dt&gt;Variable scope &lt;/dt&gt;&lt;dt&gt;Variable variables &lt;/dt&gt;&lt;dt&gt;Variables from outside  PHP&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt; &lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.variables.basics&quot;&gt;Basics&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Variables in PHP are represented by a dollar sign followed by the name of the  variable. The variable name is case-sensitive. &lt;/p&gt; &lt;p&gt;Variable names follow the same rules as other labels in PHP. A valid variable  name starts with a letter or underscore, followed by any number of letters,  numbers, or underscores. As a regular expression, it would be expressed thus:  &#39;[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*&#39; &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;For our purposes here, a letter is a-z, A-Z, and the ASCII  characters from 127 through 255 (0x7f-0xff). &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;For information on variable related functions, see the Variable Functions Reference. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3555&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$var &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Bob&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$Var  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Joe&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;$var, $Var&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;      &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// outputs  &quot;Bob, Joe&quot;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;$&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;4site &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;not yet&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;     &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// invalid;  starts with a number&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$_4site &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;not  yet&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;    &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// valid; starts with an underscore&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$täyte &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;mansikka&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;    &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// valid; &#39;ä&#39; is  (Extended) ASCII 228.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;In PHP 3, variables are always assigned by value. That is to say, when you  assign an expression to a variable, the entire value of the original expression  is copied into the destination variable. This means, for instance, that after  assigning one variable&#39;s value to another, changing one of those variables will  have no effect on the other. For more information on this kind of assignment,  see the chapter on Expressions. &lt;/p&gt; &lt;p&gt;As of PHP 4, PHP offers another way to assign values to variables: assign by reference. This means that the new  variable simply references (in other words, &quot;becomes an alias for&quot; or &quot;points  to&quot;) the original variable. Changes to the new variable affect the original, and  vice versa. This also means that no copying is performed; thus, the assignment  happens more quickly. However, any speedup will likely be noticed only in tight  loops or when assigning large arrays or  objects. &lt;/p&gt; &lt;p&gt;To assign by reference, simply prepend an ampersand (&amp;amp;) to the beginning  of the variable which is being assigned (the source variable). For instance, the  following code snippet outputs &#39;My name is Bob&#39; twice:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3564&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Bob&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;              &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Assign the value &#39;Bob&#39; to $foo&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;              &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Reference $foo via $bar.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;My  name is $bar&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Alter $bar...&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;                 &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  $foo is altered too.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;One important thing to note is that only named variables may be assigned by  reference.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3567&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;      &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// This is a  valid assignment.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;(&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;24  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;* &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Invalid; references an unnamed  expression.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()&lt;br /&gt;{&lt;br /&gt;   return &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;test&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();    &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;//  Invalid.&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/4741657912932838980/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variables.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4741657912932838980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4741657912932838980'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/variables.html' title='Variables'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-4396567303621018091</id><published>2009-01-08T17:20:00.004-08:00</published><updated>2009-01-08T17:21:08.212-08:00</updated><title type='text'>Type Juggling</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.types.type-juggling&quot;&gt;Type Juggling&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP does not require (or support) explicit type definition in variable  declaration; a variable&#39;s type is determined by the context in which that  variable is used. That is to say, if you assign a string value to variable &lt;var class=&quot;parameter&quot;&gt;$var&lt;/var&gt;, &lt;var class=&quot;parameter&quot;&gt;$var&lt;/var&gt; becomes a string. If  you then assign an integer value to &lt;var class=&quot;parameter&quot;&gt;$var&lt;/var&gt;, it becomes  an integer. &lt;/p&gt; &lt;p&gt;An example of PHP&#39;s automatic type conversion is the addition operator &#39;+&#39;.  If any of the operands is a float, then all operands are evaluated as floats,  and the result will be a float. Otherwise, the operands will be interpreted as  integers, and the result will also be an integer. Note that this does NOT change  the types of the operands themselves; the only change is in how the operands are  evaluated.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3473&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;0&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is string  (ASCII 48)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is now an  integer (2)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1.3&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is now a  float (3.3)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;10 Little  Piggies&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is integer (15)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;5 &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;+ &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;10 Small Pigs&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;     &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is  integer (15)&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;If the last two examples above seem odd, see String  conversion to numbers. &lt;/p&gt; &lt;p&gt;If you wish to force a variable to be evaluated as a certain type, see the  section on Type  casting. If you wish to change the type of a variable, see &lt;b class=&quot;function&quot;&gt;settype()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;If you would like to test any of the examples in this section, you can use  the &lt;b class=&quot;function&quot;&gt;var_dump()&lt;/b&gt;  function. &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The behaviour of an automatic conversion to array is currently  undefined. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3485&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;     &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $a is a  string&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;] = &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;f&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// What about  string offsets? What happens?&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;Since PHP (for historical reasons) supports indexing into strings via offsets  using the same syntax as array indexing, the example above leads to a problem:  should $a become an array with its first element being &quot;f&quot;, or should &quot;f&quot; become  the first character of the string $a? &lt;/p&gt; &lt;p&gt;The current versions of PHP interpret the second assignment as a string  offset identification, so $a becomes &quot;f&quot;, the result of this automatic  conversion however should be considered undefined. PHP 4 introduced the new  curly bracket syntax to access characters in string, use this syntax instead of  the one presented above:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3489&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$a    &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;abc&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;  &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $a is a string&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$a&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;} = &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;f&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $a is now &quot;afc&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;See the section titled String access by  character for more information.  &lt;/blockquote&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.types.typecasting&quot;&gt;Type Casting&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Type casting in PHP works much as it does in C: the name of the desired type  is written in parentheses before the variable which is to be cast.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3495&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo is an  integer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= (boolean) &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $bar is a boolean&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;The casts allowed are:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;(int), (integer) - cast to integer&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;(bool), (boolean) - cast to boolean&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;(float), (double), (real) - cast to float&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;(string) - cast to string&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;(array) - cast to array&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;(object) - cast to object&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p&gt;Note that tabs and spaces are allowed inside the parentheses, so the  following are functionally equivalent:  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3512&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  (int) &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= ( int ) &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$bar&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Instead of casting a variable to string, you can also enclose  the variable in double quotes.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3516&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;            &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $foo  is an integer&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$str &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;$foo&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;        &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $str is a  string&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$fst &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= (string) &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$foo&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// $fst is also a string&lt;br /&gt;&lt;br /&gt;// This prints out that  &quot;they are the same&quot;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;if (&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$fst &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=== &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$str&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;) {&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&quot;they are the same&quot;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;It may not be obvious exactly what will happen when casting between certain  types. For more info, see these sections:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;Converting to  boolean&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting to  integer&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting  to float&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting  to string&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting  to array&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting  to object&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;Converting  to resource&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;The type comparison tables  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/4396567303621018091/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/type-juggling.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4396567303621018091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/4396567303621018091'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/type-juggling.html' title='Type Juggling'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-324075770991473065</id><published>2009-01-08T17:20:00.003-08:00</published><updated>2009-01-08T17:20:47.791-08:00</updated><title type='text'>Pseudo-types used in this documentation</title><content type='html'>&lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.pseudo-types&quot;&gt;Pseudo-types used in this  documentation&lt;/a&gt;&lt;/h1&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.types.mixed&quot;&gt;mixed&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;var class=&quot;literal&quot;&gt;mixed&lt;/var&gt; indicates that a parameter may accept multiple  (but not necessarily all) types. &lt;/p&gt; &lt;p&gt;&lt;b class=&quot;function&quot;&gt;gettype()&lt;/b&gt; for  example will accept all PHP types, while &lt;b class=&quot;function&quot;&gt;str_replace()&lt;/b&gt; will accept strings and arrays. &lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.types.number&quot;&gt;number&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;var class=&quot;literal&quot;&gt;number&lt;/var&gt; indicates that a parameter can be either &lt;b class=&quot;type&quot;&gt;integer&lt;/b&gt; or &lt;b class=&quot;type&quot;&gt;float&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.types.callback&quot;&gt;callback&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Some functions like &lt;b class=&quot;function&quot;&gt;call_user_func()&lt;/b&gt; or &lt;b class=&quot;function&quot;&gt;usort()&lt;/b&gt; accept user defined callback functions as a  parameter. Callback functions can not only be simple functions but also object  methods including static class methods. &lt;/p&gt; &lt;p&gt;A PHP function is simply passed by its name as a string. You can pass any  builtin or user defined function with the exception of &lt;b class=&quot;function&quot;&gt;array()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;echo()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;empty()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;eval()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;exit()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;isset()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;list()&lt;/b&gt;, &lt;b class=&quot;function&quot;&gt;print()&lt;/b&gt; and &lt;b class=&quot;function&quot;&gt;unset()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;A method of an instantiated object is passed as an array containing an object  as the element with index 0 and a method name as the element with index 1. &lt;/p&gt; &lt;p&gt;Static class methods can also be passed without instantiating an object of  that class by passing the class name instead of an object as the element with  index 0. &lt;/p&gt; &lt;p&gt; &lt;table class=&quot;EXAMPLE&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; width=&quot;100%&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class=&quot;example&quot;&gt;&lt;a name=&quot;AEN3463&quot;&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-13. Callback function examples &lt;/b&gt;&lt;/p&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// An example callback  function&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;my_callback_function&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;() {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;hello world!&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// An  example callback method&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;class  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;MyClass &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;{&lt;br /&gt;    function &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;myCallbackMethod&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;()  {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;Hello World!&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Type 1: Simple callback&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;call_user_func&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;my_callback_function&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Type 2:  Static class method call&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;call_user_func&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(array(&lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;MyClass&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;myCallbackMethod&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(255, 128, 0);&quot;&gt;// Type  3: Object method call&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;= new &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;MyClass&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;call_user_func&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;(array(&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;$obj&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color: rgb(221, 0, 0);&quot;&gt;&#39;myCallbackMethod&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;));&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/324075770991473065/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/pseudo-types-used-in-this-documentation.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/324075770991473065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/324075770991473065'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/pseudo-types-used-in-this-documentation.html' title='Pseudo-types used in this documentation'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3864572578383860965</id><published>2009-01-08T17:20:00.001-08:00</published><updated>2009-01-08T17:20:24.434-08:00</updated><title type='text'>NULL</title><content type='html'>&lt;div class=&quot;sect1&quot;&gt; &lt;h1 class=&quot;sect1&quot;&gt;&lt;a name=&quot;language.types.null&quot;&gt;NULL&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The special &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; value represents that a  variable has no value. &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; is the only possible  value of type &lt;b class=&quot;type&quot;&gt;NULL&lt;/b&gt;.  &lt;/p&gt; &lt;div class=&quot;note&quot;&gt; &lt;blockquote class=&quot;note&quot;&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The null type was introduced in PHP 4. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;A variable is considered to be &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; if  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;it has been assigned the constant &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt;. &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;it has not been set to any value yet. &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;it has been &lt;b class=&quot;function&quot;&gt;unset()&lt;/b&gt;.  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;div class=&quot;sect2&quot;&gt; &lt;h2 class=&quot;sect2&quot;&gt;&lt;a name=&quot;language.types.null.syntax&quot;&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;There is only one value of type &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt;, and that  is the case-insensitive keyword &lt;tt class=&quot;constant&quot;&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt;.  &lt;/p&gt;&lt;div class=&quot;informalexample&quot;&gt; &lt;a name=&quot;AEN3425&quot;&gt;&lt;/a&gt; &lt;table bgcolor=&quot;#e0e0e0&quot; border=&quot;0&quot; cellpadding=&quot;5&quot;&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style=&quot;color: rgb(0, 0, 0);&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;&lt;?php&lt;br /&gt;$var &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;=  &lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 119, 0);&quot;&gt;;      &lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 0, 187);&quot;&gt;?&gt;&lt;/span&gt; &lt;/span&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;See also &lt;b class=&quot;function&quot;&gt;is_null()&lt;/b&gt;  and &lt;b class=&quot;function&quot;&gt;unset()&lt;/b&gt;.  &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3864572578383860965/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/null.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3864572578383860965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3864572578383860965'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/null.html' title='NULL'/><author><name>learn php script</name><uri>http://www.blogger.com/profile/09650724676755373376</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>