<?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: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>2011-04-21T14:04:06.923-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?max-results=100'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><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='http://img2.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>100</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="language.control-structures"&gt;Control Structures&lt;/a&gt;&lt;/h1&gt; &lt;div class="TOC"&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;if&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;else&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&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="literal"&gt;while&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;do-while&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;for&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;foreach&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;break&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;continue&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;switch&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;&lt;var class="literal"&gt;declare&lt;/var&gt; &lt;/dt&gt;&lt;dt&gt;return &lt;/dt&gt;&lt;dt&gt;&lt;b class="function"&gt;require()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class="function"&gt;include()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class="function"&gt;require_once()&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;&lt;b class="function"&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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="control-structures.if"&gt;&lt;var class="literal"&gt;if&lt;/var&gt;&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The &lt;var class="literal"&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="literal"&gt;if&lt;/var&gt; structure that is  similar to that of C:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4627"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="programlisting"&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="replaceable"&gt;expr&lt;/var&gt; is evaluated to its Boolean  value. If &lt;var class="replaceable"&gt;expr&lt;/var&gt; evaluates to &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, PHP will execute &lt;var class="replaceable"&gt;statement&lt;/var&gt;, and if it evaluates to &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; - it'll ignore it. More information about what  values evaluate to &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; can be found in the 'Converting to  boolean' section. &lt;/p&gt; &lt;p&gt;The following example would display &lt;samp class="computeroutput"&gt;a is bigger  than b&lt;/samp&gt; if &lt;var class="varname"&gt;$a&lt;/var&gt; is bigger than &lt;var class="varname"&gt;$b&lt;/var&gt;:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4642"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a is  bigger than b"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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'd want to have more than one statement to be executed  conditionally. Of course, there's no need to wrap each statement with an &lt;var class="literal"&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="computeroutput"&gt;a is bigger than b&lt;/samp&gt; if &lt;var class="varname"&gt;$a&lt;/var&gt; is  bigger than &lt;var class="varname"&gt;$b&lt;/var&gt;, and would then assign the value of &lt;var class="varname"&gt;$a&lt;/var&gt; into &lt;var class="varname"&gt;$b&lt;/var&gt;:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4651"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a is bigger than  b"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="literal"&gt;If&lt;/var&gt; statements can be nested indefinitely within  other &lt;var class="literal"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-8040141182390450142?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.type"&gt;Type Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP has a single type operator: &lt;var class="literal"&gt;instanceof&lt;/var&gt;. &lt;var class="literal"&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="literal"&gt;instanceof&lt;/var&gt; operator was introduced in PHP 5.  Before this time &lt;b class="function"&gt;is_a()&lt;/b&gt;  was used but &lt;b class="function"&gt;is_a()&lt;/b&gt; has  since been deprecated in favor of &lt;var class="literal"&gt;instanceof&lt;/var&gt;. &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN4609"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="programlisting"&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 'A';&lt;br /&gt;}&lt;br /&gt;if ($thing instanceof B) {&lt;br /&gt;   echo 'B';&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="varname"&gt;$thing&lt;/var&gt; is an &lt;b class="type"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&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="function"&gt;get_class()&lt;/b&gt; and &lt;b class="function"&gt;is_a()&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-1470231614734722489?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.array"&gt;Array Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class="table"&gt;&lt;a name="AEN4546"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-8. Array Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="literal"&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="informalexample"&gt; &lt;a name="AEN4587"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"b" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"pear"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"b" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"strawberry"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"c" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"cherry"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Union of $a and $b&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Union of \$a  and \$b: \n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Union of $b and $a&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Union of \$b  and \$a: \n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Union of $a and $b:&lt;br /&gt;array(3)  {&lt;br /&gt;  ["a"]=&gt;&lt;br /&gt;  string(5) "apple"&lt;br /&gt;  ["b"]=&gt;&lt;br /&gt;  string(6)  "banana"&lt;br /&gt;  ["c"]=&gt;&lt;br /&gt;  string(6) "cherry"&lt;br /&gt;}&lt;br /&gt;Union of $b and  $a:&lt;br /&gt;array(3) {&lt;br /&gt;  ["a"]=&gt;&lt;br /&gt;  string(4)  "pear"&lt;br /&gt;  ["b"]=&gt;&lt;br /&gt;  string(10)  "strawberry"&lt;br /&gt;  ["c"]=&gt;&lt;br /&gt;  string(6) "cherry"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN4592"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-5. Comparing arrays&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"0" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// bool(false)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3936507931107136635?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.string"&gt;String Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;There are two &lt;b class="type"&gt;string&lt;/b&gt; operators. The first is the concatenation operator  ('.'), which returns the concatenation of its right and left arguments. The  second is the concatenating assignment operator ('.='), 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="informalexample"&gt; &lt;a name="AEN4539"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"World!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// now $b contains "Hello  World!"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello  "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"World!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// now $a  contains "Hello World!"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-8602366802928270569?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.logical"&gt;Logical Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class="table"&gt;&lt;a name="AEN4486"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-7. Logical Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if both $a and $b are &lt;tt class="constant"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class="constant"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class="constant"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if $a is not &lt;tt class="constant"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if both $a and $b are &lt;tt class="constant"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; if either $a or $b is &lt;tt class="constant"&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 "and" and "or" operators is  that they operate at different precedences. (See Operator  Precedence.) &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6001667007219014899?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.increment"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The increment/decrement operators do not affect boolean values.  Decrementing &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; values has no effect too, but  incrementing them results in &lt;var class="literal"&gt;1&lt;/var&gt;. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class="table"&gt;&lt;a name="AEN4449"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-6. Increment/decrement Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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's a simple example script:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4475"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;h3&gt;Postincrement&lt;/h3&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  5: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++ . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  6: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;h3&gt;Preincrement&lt;/h3&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  6: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. ++&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  6: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;h3&gt;Postdecrement&lt;/h3&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  5: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-- . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  4: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;h3&gt;Predecrement&lt;/h3&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  4: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. --&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Should be  4: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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's convention when dealing with arithmetic operations on  character variables and not C's. For example, in Perl 'Z'+1 turns into 'AA',  while in C 'Z'+1 turns into '[' ( ord('Z') == 90, ord('[') == 91 ). Note that  character variables can be incremented but not decremented.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN4478"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'W'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;for (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$n&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$n&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$n&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++) {&lt;br /&gt;    echo  ++&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-876683670035609739?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.execution"&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't simply be dumped to  output; it can be assigned to a variable). Use of the backtick operator is  identical to &lt;b class="function"&gt;shell_exec()&lt;/b&gt;.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4431"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$output &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  `&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ls -al&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;`;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;pre&gt;$output&lt;/pre&gt;"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The backtick operator is disabled when safe mode is enabled or &lt;b class="function"&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="function"&gt;popen()&lt;/b&gt;  &lt;b class="function"&gt;proc_open()&lt;/b&gt;, and Using PHP from the commandline.  &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-4516160520980654411?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt;&lt;a name="language.operators.errorcontrol"&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="option"&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="informalexample"&gt; &lt;a name="AEN4414"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*  Intentional file error */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$my_file  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= @&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;file  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'non_existent_file'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  or&lt;br /&gt;    die (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Failed opening file: error  was '$php_errormsg'"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// this works for any expression, not just  functions:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$value &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= @&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$cache&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// will not  issue a notice if the index $key doesn't exist.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&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="function"&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="literal"&gt;if&lt;/var&gt; and &lt;var class="literal"&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="function"&gt;error_reporting()&lt;/b&gt; and the manual section for Error Handling and Logging functions. &lt;/p&gt; &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Currently the "@" 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 "@" to suppress errors from a certain  function and either it isn'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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-683991446186456522?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.comparison"&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="table"&gt;&lt;a name="AEN4260"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-4. Comparison Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="informalexample"&gt; &lt;a name="AEN4317"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 0 == 0 -&gt;  true&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"01"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 1 == 1 -&gt;  true&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;switch (&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;case  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;:&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    break;&lt;br /&gt;case &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// never reached because "a" is already matched with  0&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    break;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="table"&gt;&lt;a name="AEN4320"&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="CALSTABLE" border="1"&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="type"&gt;null&lt;/b&gt; or &lt;b class="type"&gt;string&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class="type"&gt;string&lt;/b&gt;&lt;/td&gt; &lt;td&gt;Convert &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; to "", numerical or lexical  comparison&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class="type"&gt;bool&lt;/b&gt; or &lt;b class="type"&gt;null&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;Convert to &lt;b class="type"&gt;bool&lt;/b&gt;,  &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; &lt; &lt;tt class="constant"&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="type"&gt;object&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class="type"&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="type"&gt;string&lt;/b&gt;, &lt;b class="type"&gt;resource&lt;/b&gt; or &lt;b class="type"&gt;number&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class="type"&gt;string&lt;/b&gt;, &lt;b class="type"&gt;resource&lt;/b&gt; or &lt;b class="type"&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="type"&gt;array&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b class="type"&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="type"&gt;array&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;&lt;b class="type"&gt;array&lt;/b&gt; is always  greater&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;b class="type"&gt;object&lt;/b&gt;&lt;/td&gt; &lt;td&gt;anything&lt;/td&gt; &lt;td&gt;&lt;b class="type"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN4382"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Arrays  are compared like this with standard comparison operators&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;standard_array_compare&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &lt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        return -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $op1 &lt; $op2&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) &gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $op1 &gt; $op2&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;    foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$val&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;        if (!&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_key_exists&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;            return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;null&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// uncomparable&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$val  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])  {&lt;br /&gt;            return -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        } elseif (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$val &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$op2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]) {&lt;br /&gt;            return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $op1 == $op2&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="function"&gt;strcasecmp()&lt;/b&gt;, &lt;b class="function"&gt;strcmp()&lt;/b&gt;, Array  operators, and the manual section on Types. &lt;/p&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.operators.comparison.ternary"&gt;Ternary  Operator&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Another conditional operator is the "?:" (or ternary) operator.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN4393"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Example usage for: Ternary Operator&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$action &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  (empty(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) ? &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'default'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// The  above is identical to this if/else statement&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (empty(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]))  {&lt;br /&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$action &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'default'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else  {&lt;br /&gt;     &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$action &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="literal"&gt;(expr1) ? (expr2) : (expr3)&lt;/var&gt; evaluates to  &lt;var class="replaceable"&gt;expr2&lt;/var&gt; if &lt;var class="replaceable"&gt;expr1&lt;/var&gt;  evaluates to &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, and &lt;var class="replaceable"&gt;expr3&lt;/var&gt; if &lt;var class="replaceable"&gt;expr1&lt;/var&gt; evaluates to  &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Please note that the ternary operator is a statement, and that  it doesn'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="literal"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5489823915121362029?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt;&lt;a name="language.operators.bitwise"&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' ASCII values. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4219"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;^  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;9&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs '5'&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"12"  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;^ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"9"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs the Backspace character (ascii  8)&lt;br /&gt;                 // ('1' (ascii 49)) ^ ('9' (ascii 57)) =  #8&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"hallo" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;^  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"hello"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs the ascii values #0 #4 #0 #0  #0&lt;br /&gt;                        // 'a' ^ 'e' = #4&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="table"&gt;&lt;a name="AEN4221"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-3. Bitwise Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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 "multiply by  two") &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 "divide by two")  &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Don't right shift for more than 32 bits on 32 bits systems. Don'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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3741384787992313131?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.assignment"&gt;Assignment  Operators&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The basic assignment operator is "=". Your first inclination might be to  think of this as "equal to". Don't. It really means that the left operand gets  set to the value of the expression on the rights (that is, "gets set to"). &lt;/p&gt; &lt;p&gt;The value of an assignment expression is the value assigned. That is, the  value of "$a = 3" is 3. This allows you to do some tricky things:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4206"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) +  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&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 "combined operators"  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="informalexample"&gt; &lt;a name="AEN4210"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// sets $a to 8, as  if we had said: $a = $a + 5;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello  "&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"There!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// sets $b to "Hello There!", just like $b =  $b . "There!";&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="computeroutput"&gt;$var = &amp;amp;$othervar;&lt;/samp&gt; syntax, but this is not  possible in PHP 3. 'Assignment by reference' 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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6735968310423489214?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.arithmetic"&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="table"&gt;&lt;a name="AEN4162"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-2. Arithmetic Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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 ("/") 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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Remainder &lt;var class="literal"&gt;$a % $b&lt;/var&gt; is negative for  negative &lt;var class="literal"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5906118355695600408?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.arithmetic"&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="table"&gt;&lt;a name="AEN4162"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-2. Arithmetic Operators&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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 ("/") 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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Remainder &lt;var class="literal"&gt;$a % $b&lt;/var&gt; is negative for  negative &lt;var class="literal"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6556953324794115987?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="language.operators"&gt;Operators&lt;/a&gt;&lt;/h1&gt; &lt;div class="TOC"&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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.operators.precedence"&gt;Operator  Precedence&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The precedence of an operator specifies how "tightly" it binds two  expressions together. For example, in the expression &lt;var class="literal"&gt;1 + 5 *  3&lt;/var&gt;, the answer is &lt;var class="literal"&gt;16&lt;/var&gt; and not &lt;var class="literal"&gt;18&lt;/var&gt; because the multiplication ("*") operator has a higher  precedence than the addition ("+") operator. Parentheses may be used to force  precedence, if necessary. For instance: &lt;var class="literal"&gt;(1 + 5) * 3&lt;/var&gt;  evaluates to &lt;var class="literal"&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="table"&gt;&lt;a name="AEN4038"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 15-1. Operator Precedence&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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="function"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN4149"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 15-1. Associativity&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;*  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;%  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// (3 * 3) % 5 = 4&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;true &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;? &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;true &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;? &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// (true ? 0 : true) ? 1 : 2 = 2&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $a = ($b += 3) -&gt; $a = 5, $b = 5&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Although &lt;var class="literal"&gt;!&lt;/var&gt; has a higher precedence than  &lt;var class="literal"&gt;=&lt;/var&gt;, PHP will still allow expressions similar to the  following: &lt;var class="literal"&gt;if (!$a = foo())&lt;/var&gt;, in which case the output  from &lt;var class="literal"&gt;foo()&lt;/var&gt; is put into &lt;var class="varname"&gt;$a&lt;/var&gt;.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5405898932048020305?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="language.expressions"&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 "anything that has a value". &lt;/p&gt; &lt;p&gt;The most basic forms of expressions are constants and variables. When you  type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or  in other words '5' is an expression with the value of 5 (in this case, '5' is an  integer constant). &lt;/p&gt; &lt;p&gt;After this assignment, you'd expect $a's value to be 5 as well, so if you  wrote $b = $a, you'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="informalexample"&gt; &lt;a name="AEN3984"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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're familiar with the concept of functions (if you're not, take a  look at the chapter about functions),  you'd assume that typing &lt;var class="literal"&gt;$c = foo()&lt;/var&gt; is essentially just  like writing &lt;var class="literal"&gt;$c = 5&lt;/var&gt;, and you're right. Functions are  expressions with the value of their return value. Since foo() returns 5, the  value of the expression 'foo()' is 5. Usually functions don't just return a  static value but compute something. &lt;/p&gt; &lt;p&gt;Of course, values in PHP don't have to be integers, and very often they  aren't. PHP supports four scalar value types: &lt;b class="type"&gt;integer&lt;/b&gt; values,  floating point values (&lt;b class="type"&gt;float&lt;/b&gt;), &lt;b class="type"&gt;string&lt;/b&gt; values and &lt;b class="type"&gt;boolean&lt;/b&gt; values (scalar values are values that you can't  'break' 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've already dealt with, '$a = 5'. It's  easy to see that there are two values involved here, the value of the integer  constant '5', and the value of $a which is being updated to 5 as well. But the  truth is that there's one additional value involved here, and that's the value  of the assignment itself. The assignment itself evaluates to the assigned value,  in this case 5. In practice, it means that '$a = 5', regardless of what it does,  is an expression with the value 5. Thus, writing something like '$b = ($a = 5)'  is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement).  Since assignments are parsed in a right to left order, you can also write '$b =  $a = 5'. &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 '$a++' has no value (is not an expression), and thus  you can'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 '++$variable', evaluates  to the incremented value (PHP increments the variable before reading its value,  thus the name 'pre-increment'). Post-increment, which is written '$variable++'  evaluates to the original value of $variable, before it was incremented (PHP  increments the variable after reading its value, thus the name  'post-increment'). &lt;/p&gt; &lt;p&gt;A very common type of expressions are comparison expressions. These  expressions evaluate to either &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class="constant"&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="literal"&gt;if&lt;/var&gt; statements. &lt;/p&gt; &lt;p&gt;The last example of expressions we'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 '$a++' or '++$a'. But what if you want to add more  than one to it, for instance 3? You could write '$a++' multiple times, but this  is obviously not a very efficient or comfortable way. A much more common  practice is to write '$a = $a + 3'. '$a + 3' 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 '$a += 3'. This means exactly "take the  value of $a, add 3 to it, and assign it back into $a". In addition to being  shorter and clearer, this also results in faster execution. The value of '$a +=  3', 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's  assigned into $a). Any two-place operator can be used in this  operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of  $a), '$b *= 7' (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't seen it in  other languages, the ternary conditional operator: &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN4006"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$first &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;?  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$second &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;: &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="constant"&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="informalexample"&gt; &lt;a name="AEN4012"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;double&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;{&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;*&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* assign  the value five into the variable $a and $b */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;          &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/*  post-increment, assign original value of $a&lt;br /&gt;                       (5) to $c  */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$e &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$d &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= ++&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&gt;$f &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;double&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$d&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&gt;$g &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;double&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(++&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$e&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&gt;$h &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$g &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;      &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&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 'expr' ';' that is, an expression followed by a semicolon. In  '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself.  '$b=$a=5;' 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're not interested in the  specific value of the expression, but only care about whether it means &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. The  constants &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; and &lt;tt class="constant"&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'll write &lt;var class="varname"&gt;expr&lt;/var&gt; to indicate any valid PHP expression. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5414420009073859528?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.constants.predefined"&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="constant"&gt;&lt;b&gt;__LINE__&lt;/b&gt;&lt;/tt&gt; depends  on the line that it'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="table"&gt;&lt;a name="AEN3944"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 13-1. A few "magical" PHP constants&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="constant"&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="function"&gt;get_class()&lt;/b&gt;, &lt;b class="function"&gt;get_object_vars()&lt;/b&gt;, &lt;b class="function"&gt;file_exists()&lt;/b&gt; and &lt;b class="function"&gt;function_exists()&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5550808073468777314?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="language.constants"&gt;Constants&lt;/a&gt;&lt;/h1&gt; &lt;div class="TOC"&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'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="literal"&gt;[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*&lt;/var&gt; &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3886"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Valid constant names&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"FOO"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,     &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"something"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"FOO2"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,    &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"something  else"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"FOO_BAR"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"something more"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Invalid  constant names&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"2FOO"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,    &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"something"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&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="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"__FOO__"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"something"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.constants.syntax"&gt;Syntax&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;You can define a constant by using the &lt;b class="function"&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="type"&gt;boolean&lt;/b&gt;, &lt;b class="type"&gt;integer&lt;/b&gt;, &lt;b class="type"&gt;float&lt;/b&gt; and &lt;b class="type"&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="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt;  prepend a constant with a &lt;var class="literal"&gt;$&lt;/var&gt;. You can also use the  function &lt;b class="function"&gt;constant()&lt;/b&gt;  to read a constant's value if you wish to obtain the constant's name  dynamically. Use &lt;b class="function"&gt;get_defined_constants()&lt;/b&gt; to get a list of all defined  constants. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&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="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; and &lt;var class="varname"&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="type"&gt;string&lt;/b&gt; (CONSTANT vs  "CONSTANT"). 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="function"&gt;define()&lt;/b&gt; &lt;var class="literal"&gt;bar&lt;/var&gt; as a constant). If  you simply want to check if a constant is set, use the &lt;b class="function"&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="literal"&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="function"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3934"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 13-2. Defining Constants&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"CONSTANT"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello world."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;CONSTANT&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// outputs "Hello world."&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Constant&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// outputs "Constant" and issues a  notice.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3486602157801324068?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.variables.external"&gt;Variables from outside  PHP&lt;/a&gt;&lt;/h1&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.external.form"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3801"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;&lt;form action="foo.php" method="post"&gt;&lt;br /&gt;   Name:  &lt;input type="text" name="username"&gt;&lt;br /&gt;&lt;br /&gt;   Email: &lt;input type="text" name="email"&gt;&lt;br /&gt;&lt;br /&gt;   &lt;input type="submit" name="submit" value="Submit me!"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3806"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;&lt;?php&lt;br /&gt;// Available since PHP 4.1.0&lt;br /&gt;&lt;br /&gt;  echo $_POST['username'];&lt;br /&gt;  echo $_REQUEST['username'];&lt;br /&gt;&lt;br /&gt;  import_request_variables('p', 'p_');&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['username'];&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'll use the appropriate GET predefined  variable instead. GET also applies to the QUERY_STRING (the information after  the '?' in a URL). So, for example, &lt;var class="literal"&gt;http://www.example.com/test.php?id=3&lt;/var&gt; contains GET data which  is accessible with &lt;var class="varname"&gt;$_GET['id']&lt;/var&gt;. See also $_REQUEST and &lt;b class="function"&gt;import_request_variables()&lt;/b&gt;. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Superglobal  arrays, like &lt;var class="varname"&gt;$_POST&lt;/var&gt; and &lt;var class="varname"&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="emphasis"&gt;&lt;i class="emphasis"&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's  preferred to assume it's &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;off&lt;/i&gt;&lt;/span&gt;  and code accordingly. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&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's "PHP!")  will automagically become (It\'s \"PHP!\"). Escaping is needed for DB insertion.  See also &lt;b class="function"&gt;addslashes()&lt;/b&gt;, &lt;b class="function"&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's post a form to itself and upon submission  display the data: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3832"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]) &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'action'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] ==  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'submitted'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;pre&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;a href=""&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'PHP_SELF'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]  .&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'"&gt;Please try  again&lt;/a&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&lt;/pre&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} else {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;form action="&lt;span style="&gt;&lt;?php &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'PHP_SELF'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;"  method="post"&gt;&lt;br /&gt;    Name:  &lt;input type="text" name="personal[name]"&gt;&lt;br /&gt;&lt;br /&gt;    Email: &lt;input type="text" name="personal[email]"&gt;&lt;br /&gt;&lt;br /&gt;    Beer: &lt;br /&gt;&lt;br /&gt;    &lt;select name="beer[]"&gt;&lt;br /&gt;        &lt;option value="warthog"&gt;Warthog&lt;/option&gt;&lt;br /&gt;        &lt;option value="guinness"&gt;Guinness&lt;/option&gt;&lt;br /&gt;        &lt;option value="stuttgarter"&gt;Stuttgarter  Schwabenbräu&lt;/option&gt;&lt;br /&gt;    &lt;/select&gt;&lt;br /&gt;&lt;br /&gt;    &lt;input type="hidden" name="action" value="submitted"&gt;&lt;br /&gt;    &lt;input type="submit" name="submit" value="submit me!"&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.variables.external.form.submit"&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="informalexample"&gt; &lt;a name="AEN3839"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;&lt;input type="image" src="image.gif" name="sub"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.external.cookies"&gt;HTTP  Cookies&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;PHP transparently supports HTTP cookies as defined by Netscape'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="function"&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="function"&gt;header()&lt;/b&gt; function. Cookie  data is then available in the appropriate cookie data arrays, such as &lt;var class="varname"&gt;$_COOKIE&lt;/var&gt;, &lt;var class="varname"&gt;$HTTP_COOKIE_VARS&lt;/var&gt; as well  as in &lt;var class="varname"&gt;$_REQUEST&lt;/var&gt;. See the &lt;b class="function"&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="informalexample"&gt; &lt;a name="AEN3853"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;  setcookie&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"MyCookie[foo]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Testing 1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3600&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;setcookie&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"MyCookie[bar]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Testing 2'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3600&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="function"&gt;serialize()&lt;/b&gt; or &lt;b class="function"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3859"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-11. A &lt;b class="function"&gt;setcookie()&lt;/b&gt; example&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_COOKIE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'count'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;])) {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_COOKIE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'count'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] +  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}  else {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;setcookie&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'count'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3600&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;setcookie&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Cart[$count]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$item&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;time&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3600&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.external.dot-in-names"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$varname&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ext&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* invalid  variable name */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&gt;$varname&lt;/var&gt;, followed by the string concatenation  operator, followed by the barestring (i.e. unquoted string which doesn't match  any known key or reserved words) 'ext'. Obviously, this doesn'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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.determining-type-of"&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="function"&gt;gettype()&lt;/b&gt;, &lt;b class="function"&gt;is_array()&lt;/b&gt;, &lt;b class="function"&gt;is_float()&lt;/b&gt;, &lt;b class="function"&gt;is_int()&lt;/b&gt;, &lt;b class="function"&gt;is_object()&lt;/b&gt;, and &lt;b class="function"&gt;is_string()&lt;/b&gt;. See also  the chapter on Types. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6586813664214396094?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt;&lt;a name="language.variables.variable"&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="informalexample"&gt; &lt;a name="AEN3770"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'hello'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="emphasis"&gt;&lt;i class="emphasis"&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="informalexample"&gt; &lt;a name="AEN3774"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;$&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'world'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&gt;$a&lt;/var&gt; with contents "hello" and &lt;var class="varname"&gt;$hello&lt;/var&gt; with contents "world". Therefore, this statement:  &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3779"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$a ${$a}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="informalexample"&gt; &lt;a name="AEN3782"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$a $hello"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="computeroutput"&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="varname"&gt;$$a[1]&lt;/var&gt; then  the parser needs to know if you meant to use &lt;var class="varname"&gt;$a[1]&lt;/var&gt; as a  variable, or if you wanted &lt;var class="varname"&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="varname"&gt;${$a[1]}&lt;/var&gt; for the first case and &lt;var class="varname"&gt;${$a}[1]&lt;/var&gt; for the second. &lt;/p&gt; &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Please note that variable variables cannot be used with PHP'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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-4140925421156478054?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.variables.scope"&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="informalexample"&gt; &lt;a name="AEN3680"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;include &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'b.inc'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&gt;$a&lt;/var&gt; variable will be available within the  included &lt;tt class="filename"&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="informalexample"&gt; &lt;a name="AEN3685"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* global scope */&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{ &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* reference to  local scope variable */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.scope.global"&gt;The global  keyword&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;First, an example use of &lt;var class="literal"&gt;global&lt;/var&gt;: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3694"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-1. Using global&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Sum&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    global &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Sum&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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 "3". By declaring &lt;var class="varname"&gt;$a&lt;/var&gt;  and &lt;var class="varname"&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="varname"&gt;$GLOBALS&lt;/var&gt; array. The previous example can be  rewritten as: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3703"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-2. Using &lt;var class="varname"&gt;$GLOBALS&lt;/var&gt; instead of  global&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Sum&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'b'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] + &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$GLOBALS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'b'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Sum&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&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="varname"&gt;$GLOBALS&lt;/var&gt; exists in any scope, this is because $GLOBALS is a  superglobal.  Here's an example demonstrating the power of superglobals: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3712"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test_global&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Most predefined variables aren't "super" and require&lt;br /&gt;    // 'global' to be  available to the functions local scope.&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;global &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$HTTP_POST_VARS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;   &lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$HTTP_POST_VARS&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;   &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Superglobals are available in any scope and do&lt;br /&gt;    // not require 'global'.  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="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.scope.static"&gt;Using static  variables&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Another important feature of variable scoping is the &lt;span class="emphasis"&gt;&lt;i class="emphasis"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3720"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&gt;$a&lt;/var&gt; to &lt;var class="literal"&gt;0&lt;/var&gt; and prints "0". The &lt;var class="varname"&gt;$a&lt;/var&gt;++ which increments the variable serves no purpose since  as soon as the function exits the &lt;var class="varname"&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="varname"&gt;$a&lt;/var&gt; variable is declared static: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3730"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="varname"&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="varname"&gt;$count&lt;/var&gt; to know when to stop: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3738"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;    static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;--;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3744"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 12-7. Declaring static variables&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(){&lt;br /&gt;    static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;          &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// correct &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  wrong  (as it is an expression)&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;sqrt&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;121&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// wrong  (as it is an expression  too)&lt;br /&gt;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.variables.scope.references"&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="literal"&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="informalexample"&gt; &lt;a name="AEN3754"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test_global_ref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() {&lt;br /&gt;    global &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;stdclass&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test_global_noref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()  {&lt;br /&gt;    global &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;stdclass&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test_global_ref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test_global_noref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&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="literal"&gt;static&lt;/var&gt; statement.  References are not stored statically: &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3760"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function  &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_ref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() {&lt;br /&gt;    static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Static object: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    if  (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Assign a reference to the static variable&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;new  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;stdclass&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;property&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_noref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()  {&lt;br /&gt;    static &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Static object: '&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    if  (!isset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Assign the object to the static variable&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;stdclass&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;property&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++;&lt;br /&gt;    return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj1  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_ref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$still_obj1  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_ref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_noref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$still_obj2  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;get_instance_noref&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&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; ["property"]=&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's not &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;remembered&lt;/i&gt;&lt;/span&gt;  when you call the &lt;var class="literal"&gt;&amp;amp;get_instance_ref()&lt;/var&gt; function a  second time. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3248372540714650094?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.variables.predefined"&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="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;In PHP 4.2.0 and later, the default value for the PHP directive register_globals is &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;off&lt;/i&gt;&lt;/span&gt;. This is a major change in PHP.  Having register_globals &lt;span class="emphasis"&gt;&lt;i class="emphasis"&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="varname"&gt;DOCUMENT_ROOT&lt;/var&gt; you'll use &lt;var class="varname"&gt;$_SERVER['DOCUMENT_ROOT']&lt;/var&gt; instead of &lt;var class="varname"&gt;$DOCUMENT_ROOT&lt;/var&gt;, or &lt;var class="varname"&gt;$_GET['id']&lt;/var&gt; from  the URL &lt;var class="literal"&gt;http://www.example.com/test.php?id=3&lt;/var&gt; instead of  &lt;var class="varname"&gt;$id&lt;/var&gt;, or &lt;var class="varname"&gt;$_ENV['HOME']&lt;/var&gt; instead  of &lt;var class="varname"&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 'autoglobals' or 'superglobals'. (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'll  notice how the older predefined variables (&lt;var class="varname"&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="note"&gt; &lt;blockquote class="note"&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="note"&gt; &lt;blockquote class="note"&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="variablelist"&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="varname"&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="varname"&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="varname"&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="varname"&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="varname"&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="varname"&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="varname"&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="function"&gt;import_request_variables()&lt;/b&gt;. &lt;/p&gt; &lt;div class="caution"&gt;  &lt;table class="caution" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Since PHP 4.3.0, FILE information from &lt;var class="varname"&gt;$_FILES&lt;/var&gt; does  not exist in &lt;var class="varname"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;When running on the command  line , this will &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt;  include the &lt;var class="varname"&gt;argv&lt;/var&gt; and &lt;var class="varname"&gt;argc&lt;/var&gt;  entries; these are present in the &lt;var class="varname"&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's session. Analogous to  the old &lt;var class="varname"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-7697917606089125284?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="language.variables"&gt;Variables&lt;/a&gt;&lt;/h1&gt; &lt;div class="TOC"&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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.variables.basics"&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:  '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&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="informalexample"&gt; &lt;a name="AEN3555"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$var &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Bob'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$Var  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Joe'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$var, $Var"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;      &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// outputs  "Bob, Joe"&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;$&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4site &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'not yet'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// invalid;  starts with a number&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_4site &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'not  yet'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// valid; starts with an underscore&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$täyte &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'mansikka'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// valid; 'ä' is  (Extended) ASCII 228.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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'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, "becomes an alias for" or "points  to") 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 'My name is Bob' twice:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3564"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Bob'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;              &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Assign the value 'Bob' to $foo&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;              &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Reference $foo via $bar.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"My  name is $bar"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Alter $bar...&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;                 &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  $foo is altered too.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="informalexample"&gt; &lt;a name="AEN3567"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;      &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This is a  valid assignment.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;24  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;* &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Invalid; references an unnamed  expression.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;{&lt;br /&gt;   return &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;test&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Invalid.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-4741657912932838980?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.type-juggling"&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'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="parameter"&gt;$var&lt;/var&gt;, &lt;var class="parameter"&gt;$var&lt;/var&gt; becomes a string. If  you then assign an integer value to &lt;var class="parameter"&gt;$var&lt;/var&gt;, it becomes  an integer. &lt;/p&gt; &lt;p&gt;An example of PHP's automatic type conversion is the addition operator '+'.  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="informalexample"&gt; &lt;a name="AEN3473"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"0"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is string  (ASCII 48)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is now an  integer (2)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1.3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is now a  float (3.3)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10 Little  Piggies"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is integer (15)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10 Small Pigs"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is  integer (15)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="function"&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="function"&gt;var_dump()&lt;/b&gt;  function. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&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="informalexample"&gt; &lt;a name="AEN3485"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"1"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $a is a  string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"f"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// What about  string offsets? What happens?&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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 "f", or should "f" 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 "f", 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="informalexample"&gt; &lt;a name="AEN3489"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"abc"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $a is a string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"f"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $a is now "afc"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.typecasting"&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="informalexample"&gt; &lt;a name="AEN3495"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is an  integer&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= (boolean) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $bar is a boolean&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="informalexample"&gt; &lt;a name="AEN3512"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  (int) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= ( int ) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&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="informalexample"&gt; &lt;a name="AEN3516"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;            &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo  is an integer&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$foo"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $str is a  string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fst &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= (string) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $fst is also a string&lt;br /&gt;&lt;br /&gt;// This prints out that  "they are the same"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fst &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"they are the same"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-4396567303621018091?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt;&lt;a name="language.pseudo-types"&gt;Pseudo-types used in this  documentation&lt;/a&gt;&lt;/h1&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.mixed"&gt;mixed&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;var class="literal"&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="function"&gt;gettype()&lt;/b&gt; for  example will accept all PHP types, while &lt;b class="function"&gt;str_replace()&lt;/b&gt; will accept strings and arrays. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.number"&gt;number&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;&lt;var class="literal"&gt;number&lt;/var&gt; indicates that a parameter can be either &lt;b class="type"&gt;integer&lt;/b&gt; or &lt;b class="type"&gt;float&lt;/b&gt;. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.callback"&gt;callback&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Some functions like &lt;b class="function"&gt;call_user_func()&lt;/b&gt; or &lt;b class="function"&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="function"&gt;array()&lt;/b&gt;, &lt;b class="function"&gt;echo()&lt;/b&gt;, &lt;b class="function"&gt;empty()&lt;/b&gt;, &lt;b class="function"&gt;eval()&lt;/b&gt;, &lt;b class="function"&gt;exit()&lt;/b&gt;, &lt;b class="function"&gt;isset()&lt;/b&gt;, &lt;b class="function"&gt;list()&lt;/b&gt;, &lt;b class="function"&gt;print()&lt;/b&gt; and &lt;b class="function"&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="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3463"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-13. Callback function examples &lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// An example callback  function&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;my_callback_function&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;() {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'hello world!'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// An  example callback method&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;class  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyClass &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;br /&gt;    function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;myCallbackMethod&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()  {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Hello World!'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Type 1: Simple callback&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;call_user_func&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'my_callback_function'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Type 2:  Static class method call&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;call_user_func&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'MyClass'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'myCallbackMethod'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Type  3: Object method call&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;MyClass&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;call_user_func&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(array(&amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'myCallbackMethod'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-324075770991473065?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.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="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.null"&gt;NULL&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;The special &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; value represents that a  variable has no value. &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; is the only possible  value of type &lt;b class="type"&gt;NULL&lt;/b&gt;.  &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&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="constant"&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="constant"&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="function"&gt;unset()&lt;/b&gt;.  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.null.syntax"&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;There is only one value of type &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt;, and that  is the case-insensitive keyword &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt;.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3425"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$var &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;NULL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="function"&gt;is_null()&lt;/b&gt;  and &lt;b class="function"&gt;unset()&lt;/b&gt;.  &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3864572578383860965?l=learnphpscript.blogspot.com' alt='' /&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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-2390591992026960567</id><published>2009-01-08T17:19:00.002-08:00</published><updated>2009-01-08T17:20:06.555-08:00</updated><title type='text'>Resource</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.resource"&gt;Resource&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;A resource is a special variable, holding a reference to an external  resource. Resources are created and used by special functions. See the appendix for a listing of all these functions and the  corresponding resource types. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The resource type was introduced in PHP 4  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;See also &lt;b class="function"&gt;get_resource_type()&lt;/b&gt;. &lt;/p&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.resource.casting"&gt;Converting to  resource&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;As resource types hold special handlers to opened files, database  connections, image canvas areas and the like, you cannot convert any value to a  resource. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.resource.self-destruct"&gt;Freeing  resources&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Due to the reference-counting system introduced with PHP 4's Zend Engine, it  is automatically detected when a resource is no longer referred to (just like  Java). When this is the case, all resources that were in use for this resource  are made free by the garbage collector. For this reason, it is rarely ever  necessary to free the memory manually by using some free_result function.  &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Persistent database links are special, they are &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt; destroyed by the garbage  collector. See also the section about persistent connections.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-2390591992026960567?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/2390591992026960567/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/resource.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2390591992026960567'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2390591992026960567'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/resource.html' title='Resource'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3693554552982074441</id><published>2009-01-08T17:19:00.001-08:00</published><updated>2009-01-08T17:19:46.419-08:00</updated><title type='text'>Objects</title><content type='html'>&lt;h1 class="sect1"&gt;&lt;a name="language.types.object"&gt;Objects&lt;/a&gt;&lt;/h1&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.object.init"&gt;Object  Initialization&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;To initialize an object, you use the &lt;var class="literal"&gt;new&lt;/var&gt; statement  to instantiate the object to a variable.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3372"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;class  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;br /&gt;    function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;do_foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;    {&lt;br /&gt;        echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Doing foo."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;do_foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;For a full discussion, please read the section Classes and Objects. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.object.casting"&gt;Converting to  object&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;If an object is converted to an object, it is not modified. If a value of any  other type is converted to an object, a new instance of the &lt;var class="literal"&gt;stdClass&lt;/var&gt; built in class is created. If the value was null,  the new instance will be empty. For any other value, a member variable named  &lt;var class="literal"&gt;scalar&lt;/var&gt; will contain the value.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3381"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$obj &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  (object) &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'ciao'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$obj&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;scalar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// outputs 'ciao'&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3693554552982074441?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3693554552982074441/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/objects.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3693554552982074441'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3693554552982074441'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/objects.html' title='Objects'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-9045226548860706377</id><published>2009-01-08T17:18:00.004-08:00</published><updated>2009-01-08T17:19:23.095-08:00</updated><title type='text'>Arrays</title><content type='html'>&lt;h1 class="sect1"&gt;&lt;a name="language.types.array"&gt;Arrays&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;An array in PHP is actually an ordered map. A map is a type that maps &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;values&lt;/i&gt;&lt;/span&gt; to &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;keys&lt;/i&gt;&lt;/span&gt;. This type is optimized in several ways, so you  can use it as a real array, or a list (vector), hashtable (which is an  implementation of a map), dictionary, collection, stack, queue and probably  more. Because you can have another PHP array as a value, you can also quite  easily simulate trees. &lt;/p&gt; &lt;p&gt;Explanation of those data structures is beyond the scope of this manual, but  you'll find at least one example for each of them. For more information we refer  you to external literature about this broad topic. &lt;/p&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.syntax"&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.array.syntax.array-func"&gt;Specifying with  &lt;/a&gt;&lt;b class="function"&gt;array()&lt;/b&gt;&lt;/h3&gt; &lt;p&gt;An &lt;b class="type"&gt;array&lt;/b&gt; can be  created by the &lt;b class="function"&gt;array()&lt;/b&gt;  language-construct. It takes a certain number of comma-separated &lt;var class="literal"&gt;&lt;var class="replaceable"&gt;key&lt;/var&gt; =&gt; &lt;var class="replaceable"&gt;value&lt;/var&gt;&lt;/var&gt; pairs. &lt;/p&gt; &lt;p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="synopsis"&gt;array( [&lt;var class="replaceable"&gt;key&lt;/var&gt; =&gt;] &lt;var class="replaceable"&gt;value&lt;/var&gt;&lt;br /&gt;    , ...&lt;br /&gt;    )&lt;br /&gt;// &lt;var class="replaceable"&gt;key&lt;/var&gt; may be an &lt;b class="type"&gt;integer&lt;/b&gt; or &lt;b class="type"&gt;string&lt;/b&gt;&lt;br /&gt;// &lt;var class="replaceable"&gt;value&lt;/var&gt; may be any value&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3172"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$arr &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"foo" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"bar"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;true&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"foo"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bar&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 1&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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 &lt;var class="varname"&gt;key&lt;/var&gt; may be either an &lt;var class="literal"&gt;integer&lt;/var&gt; or a &lt;b class="type"&gt;string&lt;/b&gt;. If a key is the standard representation of an &lt;b class="type"&gt;integer&lt;/b&gt;, it will be  interpreted as such (i.e. &lt;var class="literal"&gt;"8"&lt;/var&gt; will be interpreted as  &lt;var class="literal"&gt;8&lt;/var&gt;, while &lt;var class="literal"&gt;"08"&lt;/var&gt; will be  interpreted as &lt;var class="literal"&gt;"08"&lt;/var&gt;). Floats in &lt;var class="varname"&gt;key&lt;/var&gt; are truncated to &lt;b class="type"&gt;integer&lt;/b&gt;. There are no  different indexed and associative array types in PHP; there is only one array  type, which can both contain integer and string indices. &lt;/p&gt; &lt;p&gt;A value can be of any PHP type.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3186"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$arr &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"somearray" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;13 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;9&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;42&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"somearray"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  5&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"somearray"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;13&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  9&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"somearray"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  42&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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 you do not specify a key for a given value, then the maximum of the  integer indices is taken, and the new key will be that maximum value + 1. If you  specify a key that already has a value assigned to it, that value will be  overwritten.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3189"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This  array is the same as ...&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;43&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;32&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;56&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"b" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// ...this  array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;43&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;32&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;56&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"b" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;As of PHP 4.3.0, the index generation behaviour described above has changed.  Now, if you append to an array in which the current maximum key is negative,  then the next key created will be zero (&lt;var class="literal"&gt;0&lt;/var&gt;). Before, the  new index would have been set to the largest existing key + 1, the same as  positive indices are. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;Using &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; as a key will evaluate to &lt;b class="type"&gt;integer&lt;/b&gt; &lt;var class="literal"&gt;1&lt;/var&gt; as key. Using &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; as a  key will evaluate to &lt;b class="type"&gt;integer&lt;/b&gt; &lt;var class="literal"&gt;0&lt;/var&gt; as key. Using &lt;var class="literal"&gt;NULL&lt;/var&gt; as a key will evaluate to the empty string. Using the  empty string as key will create (or overwrite) a key with the empty string and  its value; it is not the same as using empty brackets. &lt;/p&gt; &lt;p&gt;You cannot use arrays or objects as keys. Doing so will result in a warning:  &lt;var class="literal"&gt;Illegal offset type&lt;/var&gt;. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.array.syntax.modifying"&gt;Creating/modifying  with square-bracket syntax&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;You can also modify an existing array by explicitly setting values in it.  &lt;/p&gt; &lt;p&gt;This is done by assigning values to the array while specifying the key in  brackets. You can also omit the key, add an empty pair of brackets ("&lt;var class="literal"&gt;[]&lt;/var&gt;") to the variable name in that case.  &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="synopsis"&gt;$arr[&lt;var class="replaceable"&gt;key&lt;/var&gt;] = &lt;var class="replaceable"&gt;value&lt;/var&gt;;&lt;br /&gt;$arr[] = &lt;var class="replaceable"&gt;value&lt;/var&gt;;&lt;br /&gt;// &lt;var class="replaceable"&gt;key&lt;/var&gt; may be an &lt;b class="type"&gt;integer&lt;/b&gt; or &lt;b class="type"&gt;string&lt;/b&gt;&lt;br /&gt;// &lt;var class="replaceable"&gt;value&lt;/var&gt; may be any value&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;If  &lt;var class="varname"&gt;$arr&lt;/var&gt; doesn't exist yet, it will be created. So this is  also an alternative way to specify an array. To change a certain value, just  assign a new value to an element specified with its key. If you want to remove a  key/value pair, you need to &lt;b class="function"&gt;unset()&lt;/b&gt; it.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3219"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$arr &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;56&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This is the same as $arr[13] =  56;&lt;br /&gt;                // at this point of the script&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"x"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;42&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This adds a new element to&lt;br /&gt;                // the  array with key "x"&lt;br /&gt;               &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;unset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This removes the element from the  array&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;unset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This deletes  the whole array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;As mentioned above, if you provide the brackets with no key  specified, then the maximum of the existing integer indices is taken, and the  new key will be that maximum value + 1 . If no integer indices exist yet, the  key will be &lt;var class="literal"&gt;0&lt;/var&gt; (zero). If you specify a key that already  has a value assigned to it, that value will be overwritten. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;As of PHP 4.3.0, the index generation behaviour described above has changed.  Now, if you append to an array in which the current maximum key is negative,  then the next key created will be zero (&lt;var class="literal"&gt;0&lt;/var&gt;). Before, the  new index would have been set to the largest existing key + 1, the same as  positive indices are. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;  &lt;p&gt;Note that the maximum integer key used for this &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;need not currently exist in the array&lt;/i&gt;&lt;/span&gt;. It simply must  have existed in the array at some time since the last time the array was  re-indexed. The following example illustrates: &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3230"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Create  a simple array.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Now  delete every item, but leave the array itself intact:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$value&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;    unset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Append  an item (note that the new key is 5, instead of 0 as you&lt;br /&gt;// might  expect).&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Re-index:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_values&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] =  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&gt;Array&lt;br /&gt;(&lt;br /&gt;   [0] =&gt; 1&lt;br /&gt;   [1] =&gt; 2&lt;br /&gt;   [2] =&gt; 3&lt;br /&gt;   [3] =&gt; 4&lt;br /&gt;   [4] =&gt; 5&lt;br /&gt;)&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;)&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;   [5] =&gt; 6&lt;br /&gt;)&lt;br /&gt;Array&lt;br /&gt;(&lt;br /&gt;   [0] =&gt; 6&lt;br /&gt;   [1] =&gt; 7&lt;br /&gt;)&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.useful-funcs"&gt;Useful  functions&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;There are quite a few useful functions for working with arrays. See the array functions section. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The &lt;b class="function"&gt;unset()&lt;/b&gt; function allows unsetting keys of an array. Be  aware that the array will NOT be reindexed. If you only use "usual integer  indices" (starting from zero, increasing by one), you can achieve the reindex  effect by using &lt;b class="function"&gt;array_values()&lt;/b&gt;.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3242"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'one'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'two'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'three'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;unset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* will produce an array that would have been defined  as&lt;br /&gt;   $a = array(1 =&gt; 'one', 3 =&gt; 'three');&lt;br /&gt;   and NOT&lt;br /&gt;   $a =  array(1 =&gt; 'one', 2 =&gt;'three');&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;array_values&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Now $b is  array(0 =&gt; 'one', 1 =&gt;'three')&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;The foreach control structure  exists specifically for arrays. It provides an easy way to traverse an array.  &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.donts"&gt;Array do's and  don'ts&lt;/a&gt;&lt;/h2&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.array.foo-bar"&gt;Why is &lt;var class="literal"&gt;$foo[bar]&lt;/var&gt; wrong?&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;You should always use quotes around a string literal array index. For  example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You  might have seen the following syntax in old scripts:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3252"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'enemy'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  etc&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;This is wrong, but it works. Then, why is it wrong? The reason is  that this code has an undefined constant (bar) rather than a string ('bar' -  notice the quotes), and PHP may in future define constants which, unfortunately  for your code, have the same name. It works because PHP automatically converts a  &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;bare string&lt;/i&gt;&lt;/span&gt; (an unquoted  string which does not correspond to any known symbol) into a string which  contains the bare string. For instance, if there is no defined constant named  &lt;tt class="constant"&gt;&lt;b&gt;bar&lt;/b&gt;&lt;/tt&gt;, then PHP will substitute in the string &lt;var class="literal"&gt;'bar'&lt;/var&gt; and use that.   &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;This does not mean to &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;always&lt;/i&gt;&lt;/span&gt; quote the key. You do not want to quote keys  which are constants or variables, as this will prevent PHP from  interpreting them. &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3262"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;error_reporting&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_ALL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ini_set&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'display_errors'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;true&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;ini_set&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'html_errors'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;false&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Simple  array:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;for  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;&lt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$count&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;++)  {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\nChecking $i:  \n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Bad: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'$i'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Good:  " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$i&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Bad: {$array['$i']}\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Good:  {$array[$i]}\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;b&gt;????: &lt;/b&gt;The above example will output:&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&gt;Checking 0:&lt;br /&gt;Notice: Undefined index:  $i in /path/to/script.html on line 9&lt;br /&gt;Bad:&lt;br /&gt;Good: 1&lt;br /&gt;Notice: Undefined index:  $i in /path/to/script.html on line 11&lt;br /&gt;Bad:&lt;br /&gt;Good: 1&lt;br /&gt;&lt;br /&gt;Checking 1:&lt;br /&gt;Notice: Undefined index:  $i in /path/to/script.html on line 9&lt;br /&gt;Bad:&lt;br /&gt;Good: 2&lt;br /&gt;Notice: Undefined index:  $i in /path/to/script.html on line 11&lt;br /&gt;Bad:&lt;br /&gt;Good: 2&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;More examples to demonstrate this fact:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3267"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Let's  show all errors&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error_reporting&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_ALL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fruit' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'apple'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'veggie' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'carrot'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Correct&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fruit'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  apple&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'veggie'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// carrot&lt;br /&gt;&lt;br /&gt;// Incorrect.  This works  but also throws a PHP error of&lt;br /&gt;// level E_NOTICE because of an undefined  constant named fruit&lt;br /&gt;//&lt;br /&gt;// Notice: Use of undefined constant fruit -  assumed 'fruit' in...&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fruit&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  apple&lt;br /&gt;&lt;br /&gt;// Let's define a constant to demonstrate what's going  on.  We&lt;br /&gt;// will assign value 'veggie' to a constant named  fruit.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;define&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fruit'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'veggie'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Notice  the difference now&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fruit'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  apple&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;fruit&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  carrot&lt;br /&gt;&lt;br /&gt;// The following is okay as it's inside a string.  Constants are  not&lt;br /&gt;// looked for within strings so no E_NOTICE error here&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello  $arr[fruit]"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;      &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Hello apple&lt;br /&gt;&lt;br /&gt;// With one exception, braces  surrounding arrays within strings&lt;br /&gt;// allows constants to be looked  for&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello {$arr[fruit]}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Hello  carrot&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello {$arr['fruit']}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Hello  apple&lt;br /&gt;&lt;br /&gt;// This will not work, results in a parse error such as:&lt;br /&gt;//  Parse error: parse error, expecting T_STRING' or T_VARIABLE' or  T_NUM_STRING'&lt;br /&gt;// This of course applies to using autoglobals in strings as  well&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello $arr['fruit']"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello  $_GET['foo']"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Concatenation is another option&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;print &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hello "  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fruit'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Hello apple&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;When you turn &lt;b class="function"&gt;error_reporting()&lt;/b&gt; up to show &lt;tt class="constant"&gt;&lt;b&gt;E_NOTICE&lt;/b&gt;&lt;/tt&gt; level errors (such as setting it to &lt;tt class="constant"&gt;&lt;b&gt;E_ALL&lt;/b&gt;&lt;/tt&gt;) then you will see these errors. By default, error_reporting is turned down  to not show them. &lt;/p&gt; &lt;p&gt;As stated in the syntax section,  there must be an expression between the square brackets ('&lt;var class="literal"&gt;[&lt;/var&gt;' and '&lt;var class="literal"&gt;]&lt;/var&gt;'). That means that you  can write things like this:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3278"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;somefunc&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)];&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;This is an example of using a function return value as the array  index. PHP also knows about constants, as you may have seen the &lt;var class="literal"&gt;E_*&lt;/var&gt; ones before.  &lt;div class="informalexample"&gt; &lt;a name="AEN3281"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_ERROR&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]   = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A fatal error  has occured"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_WARNING&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] =  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"PHP issued a warning"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_NOTICE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]  = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is just an  informal notice"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Note that &lt;var class="literal"&gt;E_ERROR&lt;/var&gt; is also a valid  identifier, just like &lt;var class="literal"&gt;bar&lt;/var&gt; in the first example. But the  last example is in fact the same as writing:  &lt;div class="informalexample"&gt; &lt;a name="AEN3285"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A fatal error  has occured"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"PHP issued a  warning"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$error_descriptions&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;8&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is just an  informal notice"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;because &lt;var class="literal"&gt;E_ERROR&lt;/var&gt; equals &lt;var class="literal"&gt;1&lt;/var&gt;, etc.   &lt;p&gt;As we already explained in the above examples, &lt;var class="literal"&gt;$foo[bar]&lt;/var&gt; still works but is wrong. It works, because &lt;var class="literal"&gt;bar&lt;/var&gt; is due to its syntax expected to be a constant  expression. However, in this case no constant with the name &lt;var class="literal"&gt;bar&lt;/var&gt; exists. PHP now assumes that you meant &lt;var class="literal"&gt;bar&lt;/var&gt; literally, as the string &lt;var class="literal"&gt;"bar"&lt;/var&gt;,  but that you forgot to write the quotes. &lt;/p&gt; &lt;div class="sect4"&gt; &lt;h4 class="sect4"&gt;&lt;a name="AEN3295"&gt;So why is it bad then?&lt;/a&gt;&lt;/h4&gt; &lt;p&gt;At some point in the future, the PHP team might want to add another constant  or keyword, or you may introduce another constant into your application, and  then you get in trouble. For example, you already cannot use the words &lt;var class="literal"&gt;empty&lt;/var&gt; and &lt;var class="literal"&gt;default&lt;/var&gt; this way, since  they are special reserved keywords. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;To reiterate, inside a double-quoted &lt;b class="type"&gt;string&lt;/b&gt;, it's valid to  not surround array indexes with quotes so &lt;var class="literal"&gt;"$foo[bar]"&lt;/var&gt;  is valid. See the above examples for details on why as well as the section on variable parsing  in strings. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.casting"&gt;Converting to  array&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;For any of the types: &lt;b class="type"&gt;integer&lt;/b&gt;, &lt;b class="type"&gt;float&lt;/b&gt;, &lt;b class="type"&gt;string&lt;/b&gt;, &lt;b class="type"&gt;boolean&lt;/b&gt; and &lt;b class="type"&gt;resource&lt;/b&gt;, if you convert a value to an &lt;b class="type"&gt;array&lt;/b&gt;, you get an array  with one element (with index 0), which is the scalar value you started with.  &lt;/p&gt; &lt;p&gt;If you convert an &lt;b class="type"&gt;object&lt;/b&gt; to an array, you get the properties (member variables)  of that object as the array's elements. The keys are the member variable names.  &lt;/p&gt; &lt;p&gt;If you convert a &lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; value to an array, you  get an empty array. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.comparing"&gt;Comparing&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;It is possible to compare arrays by &lt;b class="function"&gt;array_diff()&lt;/b&gt; and by Array operators. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.array.examples"&gt;Examples&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;The array type in PHP is very versatile, so here will be some examples to  show you the full power of arrays. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3328"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  this&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array( &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'color'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'red'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'taste' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'sweet'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'shape' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'round'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'apple'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key will  be 0&lt;br /&gt;          &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// is completely equivalent with&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'color'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] =  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'red'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'taste'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'sweet'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'shape'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'round'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]  = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'apple'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[]        = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key will  be 0&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'b'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'c'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// will result  in the array array(0 =&gt; 'a' , 1 =&gt; 'b' , 2 =&gt; 'c'),&lt;br /&gt;// or simply  array('a', 'b', 'c')&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3330"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-6. Using array()&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Array  as (property-)map&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$map &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array( &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'version'    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;              &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'OS'         &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Linux'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;              &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'lang'       &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'english'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;              &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'short_tags' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;true&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;           &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// strictly numerical keys&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$array &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;8&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;156&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;br /&gt;              &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// this is the  same as array(0 =&gt; 7, 1 =&gt; 8, ...)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$switching &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(         &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key =  0&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'a'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                            &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;11&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key = 6 (maximum of integer-indices was  5)&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'8'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key = 8  (integer!)&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'02'  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;77&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// key = '02'&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0    &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  the value 10 will be overwritten by 12&lt;br /&gt;                  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;                 &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// empty array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$empty &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array();        &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="language.types.array.examples.loop"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-7. Collection&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$colors &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'red'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'blue'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'green'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'yellow'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;foreach (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$colors &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$color&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Do you like  $color?\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&gt;Do you like red?&lt;br /&gt;Do you like blue?&lt;br /&gt;Do you like green?&lt;br /&gt;Do you like yellow?&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;Note that it is currently not possible to change the values of the array  directly in such a loop. A workaround is the following:  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="language.types.array.examples.changeloop"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-8. Collection&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;foreach  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$colors &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;as &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$color&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// won't work:&lt;br /&gt;    //$color =  strtoupper($color);&lt;br /&gt;   &lt;br /&gt;    // works:&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$colors&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$key&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strtoupper&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$color&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$colors&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&gt;Array&lt;br /&gt;(&lt;br /&gt;   [0] =&gt; RED&lt;br /&gt;   [1] =&gt; BLUE&lt;br /&gt;   [2] =&gt; GREEN&lt;br /&gt;   [3] =&gt; YELLOW&lt;br /&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;This example creates a one-based array.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3345"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-9. One-based index&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$firstquarter  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'January'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'February'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'March'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$firstquarter&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="screen"&gt;Array&lt;br /&gt;(&lt;br /&gt;   [1] =&gt; 'January'&lt;br /&gt;   [2] =&gt; 'February'&lt;br /&gt;   [3] =&gt; 'March'&lt;br /&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;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3350"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-10. Filling an array&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// fill  an array with all items from a directory&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;opendir&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'.'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;while (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;false  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;!== (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;readdir&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)))  {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$files&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] = &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$file&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;closedir&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$handle&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Arrays are ordered. You can also change the order using various sorting  functions. See the array functions section for more  information. You can count the number of items in an array using the &lt;b class="function"&gt;count()&lt;/b&gt; function. &lt;/p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3356"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-11. Sorting an array&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;sort&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$files&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;print_r&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$files&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Because the value of an array can be anything, it can also be another array.  This way you can make recursive and multi-dimensional arrays. &lt;/p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3360"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-12. Recursive and multi-dimensional arrays&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$fruits &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array ( &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"fruits"  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; array ( &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"orange"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"b" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"banana"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"c" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;br /&gt;                                     &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;),&lt;br /&gt;                  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"numbers" &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; array  ( &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;6&lt;br /&gt;                                     &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;),&lt;br /&gt;                  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"holes"   &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; array  (      &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"first"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                       &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"second"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,&lt;br /&gt;                                            &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"third"&lt;br /&gt;                                     &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)&lt;br /&gt;                );&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Some examples to address values in the array above &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruits&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"holes"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];    &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// prints "second"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruits&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"fruits"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"a"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// prints  "orange"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;unset(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruits&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"holes"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// remove "first"&lt;br /&gt;&lt;br /&gt;// Create a new  multi-dimensional array&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$juices&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"apple"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"green"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] =  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"good"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;You should be aware that array assignment always involves value copying. You  need to use the reference operator to copy an array by reference.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3364"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$arr1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr2  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] =  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $arr2 is changed,&lt;br /&gt;             //  $arr1 is still array(2, 3)&lt;br /&gt;            &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr3 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &amp;amp;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[] =  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// now $arr1 and $arr3 are the  same&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-9045226548860706377?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/9045226548860706377/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arrays.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/9045226548860706377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/9045226548860706377'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/arrays.html' title='Arrays'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3682500574847965182</id><published>2009-01-08T17:18:00.003-08:00</published><updated>2009-01-08T17:18:54.754-08:00</updated><title type='text'>Strings</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.string"&gt;Strings&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;A &lt;b class="type"&gt;string&lt;/b&gt; is series  of characters. In PHP, a character is the same as a byte, that is, there are  exactly 256 different characters possible. This also implies that PHP has no  native support of Unicode. See &lt;b class="function"&gt;utf8_encode()&lt;/b&gt; and &lt;b class="function"&gt;utf8_decode()&lt;/b&gt; for some Unicode support. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;It is no problem for a string to become very large. There is no  practical bound to the size of strings imposed by PHP, so there is no reason at  all to worry about long strings. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.string.syntax"&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;A string literal can be specified in three different ways.  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;single  quoted &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;double  quoted &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;heredoc  syntax &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.string.syntax.single"&gt;Single  quoted&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;The easiest way to specify a simple string is to enclose it in single quotes  (the character &lt;var class="literal"&gt;'&lt;/var&gt;). &lt;/p&gt; &lt;p&gt;To specify a literal single quote, you will need to escape it with a  backslash (&lt;var class="literal"&gt;\&lt;/var&gt;), like in many other languages. If a  backslash needs to occur before a single quote or at the end of the string, you  need to double it. Note that if you try to escape any other character, the  backslash will also be printed! So usually there is no need to escape the  backslash itself.  &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;In PHP 3, a warning will be issued at the &lt;var class="literal"&gt;E_NOTICE&lt;/var&gt; level when this happens. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Unlike the two other syntaxes, variables and escape sequences for special  characters will &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt; be  expanded when they occur in single quoted strings. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN2964"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'this is a simple string'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'You  can also have embedded newlines in&lt;br /&gt;strings this way as it is&lt;br /&gt;okay to  do'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs: Arnold once said: "I'll be  back"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Arnold once said: "I\'ll be back"'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs:  You deleted C:\*.*?&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'You deleted C:\\*.*?'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs:  You deleted C:\*.*?&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'You deleted C:\*.*?'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs:  This will not expand: \n a newline&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'This will not expand: \n a  newline'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Outputs: Variables do not $expand  $either&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Variables do not $expand $either'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.string.syntax.double"&gt;Double  quoted&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;If the string is enclosed in double-quotes ("), PHP understands more escape  sequences for special characters: &lt;/p&gt; &lt;div class="table"&gt;&lt;a name="AEN2969"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;???? 11-1. Escaped characters&lt;/b&gt;&lt;/p&gt; &lt;table class="CALSTABLE" border="1"&gt; &lt;colgroup&gt; &lt;col&gt; &lt;col&gt; &lt;/colgroup&gt;&lt;thead&gt; &lt;tr&gt; &lt;th&gt;sequence&lt;/th&gt; &lt;th&gt;meaning&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\n&lt;/var&gt;&lt;/td&gt; &lt;td&gt;linefeed (LF or 0x0A (10) in ASCII)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\r&lt;/var&gt;&lt;/td&gt; &lt;td&gt;carriage return (CR or 0x0D (13) in ASCII)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\t&lt;/var&gt;&lt;/td&gt; &lt;td&gt;horizontal tab (HT or 0x09 (9) in ASCII)&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\\&lt;/var&gt;&lt;/td&gt; &lt;td&gt;backslash&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\$&lt;/var&gt;&lt;/td&gt; &lt;td&gt;dollar sign&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\"&lt;/var&gt;&lt;/td&gt; &lt;td&gt;double-quote&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\[0-7]{1,3}&lt;/var&gt;&lt;/td&gt; &lt;td&gt;the sequence of characters matching the regular expression is a character in  octal notation &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;var class="literal"&gt;\x[0-9A-Fa-f]{1,2}&lt;/var&gt;&lt;/td&gt; &lt;td&gt;the sequence of characters matching the regular expression is a character in  hexadecimal notation &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;Again, if you try to escape any other character, the backslash will be  printed too! &lt;/p&gt; &lt;p&gt;But the most important feature of double-quoted strings is the fact that  variable names will be expanded. See string  parsing for details. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.string.syntax.heredoc"&gt;Heredoc&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Another way to delimit strings is by using heredoc syntax ("&lt;&lt;&lt;").  One should provide an identifier after &lt;var class="literal"&gt;&lt;&lt;&lt;&lt;/var&gt;,  then the string, and then the same identifier to close the quotation. &lt;/p&gt; &lt;p&gt;The closing identifier &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;must&lt;/i&gt;&lt;/span&gt;  begin in the first column of the line. Also, the identifier used must follow the  same naming rules as any other label in PHP: it must contain only alphanumeric  characters and underscores, and must start with a non-digit character or  underscore. &lt;/p&gt; &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;It is very important to note that the line with the closing identifier  contains no other characters, except &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;possibly&lt;/i&gt;&lt;/span&gt; a semicolon (&lt;var class="literal"&gt;;&lt;/var&gt;).  That means especially that the identifier &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;may not be indented&lt;/i&gt;&lt;/span&gt;, and there may not be any spaces  or tabs after or before the semicolon. It's also important to realize that the  first character before the closing identifier must be a newline as defined by  your operating system. This is &lt;var class="literal"&gt;\r&lt;/var&gt; on Macintosh for  example. &lt;/p&gt; &lt;p&gt;If this rule is broken and the closing identifier is not "clean" then it's  not considered to be a closing identifier and PHP will continue looking for one.  If in this case a proper closing identifier is not found then a parse error will  result with the line number being at the end of the script. &lt;/p&gt; &lt;p&gt;It is not allowed to use heredoc syntax in initializing class members. Use  other string syntaxes instead.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3026"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-3. Invalid example&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;class  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;br /&gt;    public &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;&lt;&lt;EOT&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;bar&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;EOT;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;p&gt;Heredoc text behaves just like a double-quoted string, without the  double-quotes. This means that you do not need to escape quotes in your here  docs, but you can still use the escape codes listed above. Variables are  expanded, but the same care must be taken when expressing complex variables  inside a heredoc as with strings.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3030"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-4. Heredoc string quoting example&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$str &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;&lt;&lt;EOD&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;Example of  string&lt;br /&gt;spanning multiple lines&lt;br /&gt;using heredoc syntax.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;EOD;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;/* More  complex example, with variables. */&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;class  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;br /&gt;    var &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    var  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;    function &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;()&lt;br /&gt;    {&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$this&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Foo'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$this&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;bar &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Bar1'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Bar2'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;, &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Bar3'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= new  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;();&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$name  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'MyName'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo  &lt;&lt;&lt;EOT&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;My name is "$name". I am  printing some $foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;foo.&lt;br /&gt;Now, I am printing some &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;-&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;bar&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]}&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;.&lt;br /&gt;This should  print a capital 'A': &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;\x41&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;EOT;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Heredoc support was added in PHP 4.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.string.parsing"&gt;Variable parsing&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;When a string is specified in double quotes or with heredoc, variables are parsed within it. &lt;/p&gt; &lt;p&gt;There are two types of syntax: a simple  one and a complex  one. The simple syntax is the most common and convenient. It provides a way to  parse a variable, an &lt;b class="type"&gt;array&lt;/b&gt; value, or an object property. &lt;/p&gt; &lt;p&gt;The complex syntax was introduced in PHP 4, and can be recognised by the  curly braces surrounding the expression. &lt;/p&gt; &lt;div class="sect4"&gt; &lt;h4 class="sect4"&gt;&lt;a name="language.types.string.parsing.simple"&gt;Simple  syntax&lt;/a&gt;&lt;/h4&gt; &lt;p&gt;If a dollar sign (&lt;var class="literal"&gt;$&lt;/var&gt;) is encountered, the parser will  greedily take as many tokens as possible to form a valid variable name. Enclose  the variable name in curly braces if you want to explicitly specify the end of  the name. &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3049"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$beer &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Heineken'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"$beer's  taste is great"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// works, "'" is an invalid character for  varnames&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"He drank some $beers"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// won't work,  's' is a valid character for varnames&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"He drank some  ${beer}s"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"He drank some {$beer}s"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Similarly, you can also have an &lt;b class="type"&gt;array&lt;/b&gt; index or an object property parsed. With array indices,  the closing square bracket (&lt;var class="literal"&gt;]&lt;/var&gt;) marks the end of the  index. For object properties the same rules apply as to simple variables, though  with object properties there doesn't exist a trick like the one with variables.  &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3055"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// These  examples are specific to using arrays inside of strings.&lt;br /&gt;// When outside of a  string, always quote your array string keys&lt;br /&gt;// and do not use {braces} when  outside of strings either.&lt;br /&gt;&lt;br /&gt;// Let's show all errors&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error_reporting&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_ALL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruits  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= array(&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'strawberry' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt;  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'red'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;,  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'banana' &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=&gt; &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'yellow'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works  but note that this works differently outside string-quotes&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A banana is  $fruits[banana]."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A banana is  {$fruits['banana']}."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works but PHP looks for a constant named banana  first&lt;br /&gt;// as described below.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A banana is {$fruits[banana]}."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Won't  work, use braces.  This results in a parse error.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A banana is  $fruits['banana']."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"A banana is " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$fruits&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'banana'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;] . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This square is $square-&gt;width meters  broad."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Won't work. For a solution, see the complex  syntax.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This square is $square-&gt;width00 centimeters  broad."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;For anything more complex, you should use the complex syntax. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect4"&gt; &lt;h4 class="sect4"&gt;&lt;a name="language.types.string.parsing.complex"&gt;Complex (curly)  syntax&lt;/a&gt;&lt;/h4&gt; &lt;p&gt;This isn't called complex because the syntax is complex, but because you can  include complex expressions this way. &lt;/p&gt; &lt;p&gt;In fact, you can include any value that is in the namespace in strings with  this syntax. You simply write the expression the same way as you would outside  the string, and then include it in { and }. Since you can't escape '{', this  syntax will only be recognised when the $ is immediately following the {. (Use  "{\$" or "\{$" to get a literal "{$"). Some examples to make it clear: &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3062"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Let's  show all errors&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;error_reporting&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;E_ALL&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$great  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'fantastic'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Won't  work, outputs: This is { fantastic}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is { $great}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works,  outputs: This is fantastic&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is {$great}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is  ${great}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This square is {$square-&gt;width}00  centimeters broad."&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Works&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This works: {$arr[4][3]}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// This is  wrong for the same reason as $foo[bar] is wrong&lt;br /&gt;// outside a string.  In  other words, it will still work but&lt;br /&gt;// because PHP first looks for a constant  named foo, it will&lt;br /&gt;// throw an error of level E_NOTICE (undefined  constant).&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This is wrong: {$arr[foo][3]}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Works.  When using multi-dimensional arrays, always use&lt;br /&gt;// braces around  arrays when inside of strings&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This works: {$arr['foo'][3]}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  Works.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This works: " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;.  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$arr&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'foo'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;][&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"You  can even write {$obj-&gt;values[3]-&gt;name}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;br /&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"This  is the value of the var named $name: {${$name}}"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.string.substr"&gt;String access and  modification by character&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Characters within strings may be accessed and modified by specifying the  zero-based offset of the desired character after the string in curly braces.  &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;For backwards compatibility, you can still use array-brackets  for the same purpose. However, this syntax is deprecated as of PHP 4.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN3070"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-5. Some string examples&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Get  the first character of a string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'This  is a test.'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$first &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;};&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Get the  third character of a string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$third  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;};&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Get the  last character of a string.&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'This  is still a test.'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$last &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}; &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// Modify the last character of a  string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'Look at the  sea'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;{&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strlen&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)-&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} = &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'e'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;         &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.string.useful-funcs"&gt;Useful functions and  operators&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Strings may be concatenated using the '.' (dot) operator. Note that the '+'  (addition) operator will not work for this. Please see String operators for more information.  &lt;/p&gt; &lt;p&gt;There are a lot of useful functions for string modification. &lt;/p&gt; &lt;p&gt;See the string functions section for general  functions, the regular expression functions for advanced find&amp;amp;replacing (in  two tastes: Perl and POSIX  extended). &lt;/p&gt; &lt;p&gt;There are also functions for URL-strings, and  functions to encrypt/decrypt strings (mcrypt and  mhash). &lt;/p&gt; &lt;p&gt;Finally, if you still didn't find what you're looking for, see also the character type functions. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.string.casting"&gt;Converting to  string&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;You can convert a value to a string using the &lt;var class="literal"&gt;(string)&lt;/var&gt; cast, or the &lt;b class="function"&gt;strval()&lt;/b&gt; function. String conversion is automatically  done in the scope of an expression for you where a string is needed. This  happens when you use the &lt;b class="function"&gt;echo()&lt;/b&gt; or &lt;b class="function"&gt;print()&lt;/b&gt; functions, or when you compare a variable value  to a string. Reading the manual sections on Types and Type Juggling will make the  following clearer. See also &lt;b class="function"&gt;settype()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;A &lt;b class="type"&gt;boolean&lt;/b&gt; &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; value is converted to the string &lt;var class="literal"&gt;"1"&lt;/var&gt;, the &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; value is  represented as &lt;var class="literal"&gt;""&lt;/var&gt; (empty string). This way you can  convert back and forth between boolean and string values. &lt;/p&gt; &lt;p&gt;An &lt;b class="type"&gt;integer&lt;/b&gt; or a  floating point number (&lt;b class="type"&gt;float&lt;/b&gt;) is converted to a string representing the number with  its digits (including the exponent part for floating point numbers). &lt;/p&gt; &lt;p&gt;Arrays are always converted to the string &lt;var class="literal"&gt;"Array"&lt;/var&gt;,  so you cannot dump out the contents of an &lt;b class="type"&gt;array&lt;/b&gt; with &lt;b class="function"&gt;echo()&lt;/b&gt; or &lt;b class="function"&gt;print()&lt;/b&gt; to see what is inside them. To view one element,  you'd do something like &lt;var class="literal"&gt;echo $arr['foo']&lt;/var&gt;. See below for  tips on dumping/viewing the entire contents. &lt;/p&gt; &lt;p&gt;Objects are always converted to the string &lt;var class="literal"&gt;"Object"&lt;/var&gt;.  If you would like to print out the member variable values of an &lt;b class="type"&gt;object&lt;/b&gt; for debugging  reasons, read the paragraphs below. If you would like to find out the class name  of which an object is an instance of, use &lt;b class="function"&gt;get_class()&lt;/b&gt;. As of PHP 5, __toString() method is used if  applicable. &lt;/p&gt; &lt;p&gt;Resources are always converted to strings with the structure &lt;var class="literal"&gt;"Resource id #1"&lt;/var&gt; where &lt;var class="literal"&gt;1&lt;/var&gt; is the  unique number of the &lt;b class="type"&gt;resource&lt;/b&gt; assigned by PHP during runtime. If you would like to  get the type of the resource, use &lt;b class="function"&gt;get_resource_type()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;&lt;tt class="constant"&gt;&lt;b&gt;NULL&lt;/b&gt;&lt;/tt&gt; is always converted to an empty string.  &lt;/p&gt; &lt;p&gt;As you can see above, printing out the arrays, objects or resources does not  provide you any useful information about the values themselves. Look at the  functions &lt;b class="function"&gt;print_r()&lt;/b&gt;  and &lt;b class="function"&gt;var_dump()&lt;/b&gt; for  better ways to print out values for debugging. &lt;/p&gt; &lt;p&gt;You can also convert PHP values to strings to store them permanently. This  method is called serialization, and can be done with the function &lt;b class="function"&gt;serialize()&lt;/b&gt;. You can  also serialize PHP values to XML structures, if you have WDDX support in your PHP setup. &lt;/p&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.string.conversion"&gt;String conversion to  numbers&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;When a string is evaluated as a numeric value, the resulting value and type  are determined as follows. &lt;/p&gt; &lt;p&gt;The string will evaluate as a &lt;b class="type"&gt;float&lt;/b&gt; if it contains any of the characters '.', 'e', or 'E'.  Otherwise, it will evaluate as an integer. &lt;/p&gt; &lt;p&gt;The value is given by the initial portion of the string. If the string starts  with valid numeric data, this will be the value used. Otherwise, the value will  be 0 (zero). Valid numeric data is an optional sign, followed by one or more  digits (optionally containing a decimal point), followed by an optional  exponent. The exponent is an 'e' or 'E' followed by one or more digits. &lt;/p&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN3136"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10.5"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;                &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  $foo is float (11.5)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"-1.3e3"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;              &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  $foo is float (-1299)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"bob-1.3e3"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;           &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo  is integer (1)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"bob3"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;                &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  $foo is integer (1)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10 Small  Pigs"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;       &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is integer (11)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10.2 Little Piggies"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is float  (14.2)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10.0 pigs "  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;          &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is  float (11)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"10.0 pigs "  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+ &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1.0&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// $foo is  float (11)    &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;For more information on this conversion, see the Unix manual page for  strtod(3). &lt;/p&gt; &lt;p&gt;If you would like to test any of the examples in this section, you can cut  and paste the examples and insert the following line to see for yourself what's  going on:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN3140"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"\$foo==$foo; type is " &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;. &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;gettype  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$foo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) . &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;br /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Do not expect to get the code of one character by converting it to integer  (as you would do in C for example). Use the functions &lt;b class="function"&gt;ord()&lt;/b&gt; and &lt;b class="function"&gt;chr()&lt;/b&gt; to convert between  charcodes and characters. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3682500574847965182?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3682500574847965182/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/strings.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3682500574847965182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3682500574847965182'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/strings.html' title='Strings'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-7720781500283466179</id><published>2009-01-08T17:18:00.001-08:00</published><updated>2009-01-08T17:18:14.554-08:00</updated><title type='text'>Floating point numbers</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.float"&gt;Floating point numbers&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Floating point numbers (AKA "floats", "doubles" or "real numbers") can be  specified using any of the following syntaxes:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2906"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1.234&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$b &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1.2e3&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$c &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7E-10&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Formally:  &lt;div class="informalexample"&gt; &lt;a name="AEN2908"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;LNUM          [0-9]+&lt;br /&gt;DNUM          ([0-9]*[\.]{LNUM})  | ({LNUM}[\.][0-9]*)&lt;br /&gt;EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]?  {LNUM})&lt;/span&gt; &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;The size of a float is platform-dependent, although a maximum of  ~1.8e308 with a precision of roughly 14 decimal digits is a common value (that's  64 bit IEEE format).   &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;&lt;a name="warn.float-precision"&gt;&lt;/a&gt;Floating point  precision&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;It is quite usual that simple decimal fractions like &lt;var class="literal"&gt;0.1&lt;/var&gt; or &lt;var class="literal"&gt;0.7&lt;/var&gt; cannot be converted into  their internal binary counterparts without a little loss of precision. This can  lead to confusing results: for example, &lt;var class="literal"&gt;floor((0.1+0.7)*10)&lt;/var&gt; will usually return &lt;var class="literal"&gt;7&lt;/var&gt; instead of the expected &lt;var class="literal"&gt;8&lt;/var&gt; as the  result of the internal representation really being something like &lt;var class="literal"&gt;7.9999999999...&lt;/var&gt;. &lt;/p&gt; &lt;p&gt;This is related to the fact that it is impossible to exactly express some  fractions in decimal notation with a finite number of digits. For instance, &lt;var class="literal"&gt;1/3&lt;/var&gt; in decimal form becomes &lt;var class="literal"&gt;0.3333333. .  .&lt;/var&gt;. &lt;/p&gt; &lt;p&gt;So never trust floating number results to the last digit and never compare  floating point numbers for equality. If you really need higher precision, you  should use the arbitrary precision math functions or  gmp functions instead.  &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.float.casting"&gt;Converting to  float&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;For information on when and how strings are converted to floats, see the  section titled String  conversion to numbers. For values of other types, the conversion is the same  as if the value would have been converted to integer and then to float. See the  Converting  to integer section for more information. As of PHP 5, notice is thrown if  you try to convert object to float. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-7720781500283466179?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/7720781500283466179/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/floating-point-numbers.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7720781500283466179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7720781500283466179'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/floating-point-numbers.html' title='Floating point numbers'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-7264495421258591999</id><published>2009-01-08T17:17:00.001-08:00</published><updated>2009-01-08T17:17:53.466-08:00</updated><title type='text'>Integers</title><content type='html'>&lt;h1 class="sect1"&gt;&lt;a name="language.types.integer"&gt;Integers&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;An &lt;b class="type"&gt;integer&lt;/b&gt; is a  number of the set Z = {..., -2, -1, 0, 1, 2, ...}. &lt;/p&gt; &lt;p&gt;See also: Arbitrary length integer / GMP, Floating point numbers, and Arbitrary precision / BCMath &lt;/p&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.integer.syntax"&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Integers can be specified in decimal (10-based), hexadecimal (16-based) or  octal (8-based) notation, optionally preceded by a sign (- or +). &lt;/p&gt; &lt;p&gt;If you use the octal notation, you must precede the number with a &lt;var class="literal"&gt;0&lt;/var&gt; (zero), to use hexadecimal notation precede the number  with &lt;var class="literal"&gt;0x&lt;/var&gt;.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN2830"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-1. Integer literals&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1234&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// decimal number&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;123&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// a negative number&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0123&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// octal number (equivalent to 83  decimal)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$a &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0x1A&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// hexadecimal  number (equivalent to 26 decimal)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Formally  the possible structure for integer literals is:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2833"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="programlisting"&gt;decimal     : [1-9][0-9]*&lt;br /&gt;           | 0&lt;br /&gt;&lt;br /&gt;hexadecimal : 0[xX][0-9a-fA-F]+&lt;br /&gt;&lt;br /&gt;octal       : 0[0-7]+&lt;br /&gt;&lt;br /&gt;integer     : [+-]?decimal&lt;br /&gt;           | [+-]?hexadecimal&lt;br /&gt;           | [+-]?octal&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;The size of an integer is platform-dependent, although a maximum  value of about two billion is the usual value (that's 32 bits signed). PHP does  not support unsigned integers.   &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;If an invalid digit is passed to octal integer (i.e. 8 or 9), the rest of the  number is ignored.  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN2837"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 11-2. Octal weirdness&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;01090&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// 010 octal = 8  decimal&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.integer.overflow"&gt;Integer  overflow&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;If you specify a number beyond the bounds of the &lt;b class="type"&gt;integer&lt;/b&gt; type, it will  be interpreted as a &lt;b class="type"&gt;float&lt;/b&gt; instead. Also, if you perform an operation that results  in a number beyond the bounds of the &lt;b class="type"&gt;integer&lt;/b&gt; type, a &lt;b class="type"&gt;float&lt;/b&gt; will be returned instead.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2847"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$large_number &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2147483647&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$large_number&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// output:  int(2147483647)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$large_number  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2147483648&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$large_number&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// output:  float(2147483648)&lt;br /&gt;&lt;br /&gt;// this doesn't go for hexadecimal specified  integers:&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;( &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0x100000000  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  output: int(2147483647)&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$million  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1000000&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$large_number  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;50000  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;* &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$million&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$large_number&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// output:  float(50000000000)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Unfortunately, there was a bug in PHP so that this does not always work  correctly when there are negative numbers involved. For example: when you do  &lt;var class="literal"&gt;-50000 * $million&lt;/var&gt;, the result will be &lt;var class="literal"&gt;-429496728&lt;/var&gt;. However, when both operands are positive there  is no problem. &lt;/p&gt; &lt;p&gt;This is solved in PHP 4.1.0. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;  &lt;p&gt;There is no integer division operator in PHP. &lt;var class="literal"&gt;1/2&lt;/var&gt;  yields the &lt;b class="type"&gt;float&lt;/b&gt; &lt;var class="literal"&gt;0.5&lt;/var&gt;. You can cast the value to an integer to always round it  downwards, or you can use the &lt;b class="function"&gt;round()&lt;/b&gt; function.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2859"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);         &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  float(3.5714285714286)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((int)  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  int(3)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;round&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;25&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;/&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;));  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// float(4) &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.integer.casting"&gt;Converting to  integer&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;To explicitly convert a value to &lt;b class="type"&gt;integer&lt;/b&gt;, use either the &lt;var class="literal"&gt;(int)&lt;/var&gt; or the  &lt;var class="literal"&gt;(integer)&lt;/var&gt; cast. However, in most cases you do not need  to use the cast, since a value will be automatically converted if an operator,  function or control structure requires an &lt;b class="type"&gt;integer&lt;/b&gt; argument. You  can also convert a value to integer with the function &lt;b class="function"&gt;intval()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;See also type-juggling. &lt;/p&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.integer.casting.from-boolean"&gt;From &lt;/a&gt;booleans&lt;/h3&gt; &lt;p&gt;&lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; will yield &lt;var class="literal"&gt;0&lt;/var&gt;  (zero), and &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; will yield &lt;var class="literal"&gt;1&lt;/var&gt; (one). &lt;/p&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.integer.casting.from-float"&gt;From &lt;/a&gt;floating point numbers&lt;/h3&gt; &lt;p&gt;When converting from float to integer, the number will be rounded &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;towards zero&lt;/i&gt;&lt;/span&gt;. &lt;/p&gt; &lt;p&gt;If the float is beyond the boundaries of integer (usually &lt;var class="literal"&gt;+/- 2.15e+9 = 2^31&lt;/var&gt;), the result is undefined, since the  float hasn't got enough precision to give an exact integer result. No warning,  not even a notice will be issued in this case! &lt;/p&gt; &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Never cast an unknown fraction to &lt;b class="type"&gt;integer&lt;/b&gt;, as this can sometimes lead to unexpected results.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2889"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  (int) ( (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0.1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;0.7&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) * &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;10 &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// echoes  7!&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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 for more information the warning about  float-precision.  &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.integer.casting.from-string"&gt;From  strings&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;See String  conversion to numbers &lt;/p&gt;&lt;/div&gt; &lt;div class="sect3"&gt; &lt;h3 class="sect3"&gt;&lt;a name="language.types.integer.casting.from-other"&gt;From other  types&lt;/a&gt;&lt;/h3&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="caution"&gt;  &lt;table class="caution" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;Behaviour of converting to integer is undefined for other types. Currently,  the behaviour is the same as if the value was first converted to  boolean. However, do &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt;  rely on this behaviour, as it can change without notice. &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-7264495421258591999?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/7264495421258591999/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/integers.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7264495421258591999'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7264495421258591999'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/integers.html' title='Integers'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-7867723620880959004</id><published>2009-01-08T17:16:00.002-08:00</published><updated>2009-01-08T17:17:27.785-08:00</updated><title type='text'>Booleans</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.boolean"&gt;Booleans&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;This is the easiest type. A &lt;b class="type"&gt;boolean&lt;/b&gt; expresses a truth value. It can be either &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The boolean type was introduced in PHP 4.  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.boolean.syntax"&gt;Syntax&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;To specify a boolean literal, use either the keyword &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; or &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. Both  are case-insensitive.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2764"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$foo &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;True&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// assign the value TRUE to  $foo&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;Usually you use some kind of operator  which returns a &lt;b class="type"&gt;boolean&lt;/b&gt; value, and then pass it on to a control structure.  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2770"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// == is  an operator which test&lt;br /&gt;// equality and returns a boolean&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$action  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"show_version"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"The version is  1.23"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// this is not necessary...&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$show_separators  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TRUE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    echo  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  ...because you can simply type&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$show_separators&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"&lt;hr /&gt;\n"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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; &lt;div class="sect2"&gt; &lt;h2 class="sect2"&gt;&lt;a name="language.types.boolean.casting"&gt;Converting to  boolean&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;To explicitly convert a value to &lt;b class="type"&gt;boolean&lt;/b&gt;, use either the &lt;var class="literal"&gt;(bool)&lt;/var&gt; or  the &lt;var class="literal"&gt;(boolean)&lt;/var&gt; cast. However, in most cases you do not  need to use the cast, since a value will be automatically converted if an  operator, function or control structure requires a &lt;b class="type"&gt;boolean&lt;/b&gt; argument. &lt;/p&gt; &lt;p&gt;See also Type Juggling. &lt;/p&gt; &lt;p&gt;When converting to &lt;b class="type"&gt;boolean&lt;/b&gt;, the following values are considered &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;the boolean &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt; itself&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;the integer 0 (zero) &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;the float 0.0 (zero) &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;the empty string, and the string "0"&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;an array with zero elements&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;an object with zero member variables  (PHP 4 only)&lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;the special type NULL (including unset  variables) &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;Every other value is considered &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; (including any resource).  &lt;div class="warning"&gt;  &lt;table class="warning" border="1" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td align="middle"&gt;&lt;b&gt;?????&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt; &lt;p&gt;&lt;var class="literal"&gt;-1&lt;/var&gt; is considered &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt;, like any other non-zero (whether negative or  positive) number! &lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt; &lt;div class="informalexample"&gt; &lt;a name="AEN2814"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;""&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(false)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;1&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);         &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) -&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);        &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"foo"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;2.3e5&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool) array(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool)  array());   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// bool(false)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;var_dump&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;((bool)  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"false"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;//  bool(true)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-7867723620880959004?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/7867723620880959004/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/booleans.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7867723620880959004'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7867723620880959004'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/booleans.html' title='Booleans'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-2054627258144669620</id><published>2009-01-08T17:16:00.001-08:00</published><updated>2009-01-08T17:16:53.148-08:00</updated><title type='text'>Types</title><content type='html'>&lt;h1&gt;&lt;a name="language.types"&gt;Types&lt;/a&gt;&lt;/h1&gt; &lt;div class="TOC"&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;Introduction &lt;/dt&gt;&lt;dt&gt;Booleans &lt;/dt&gt;&lt;dt&gt;Integers &lt;/dt&gt;&lt;dt&gt;Floating point numbers &lt;/dt&gt;&lt;dt&gt;Strings &lt;/dt&gt;&lt;dt&gt;Arrays &lt;/dt&gt;&lt;dt&gt;Objects &lt;/dt&gt;&lt;dt&gt;Resource &lt;/dt&gt;&lt;dt&gt;NULL &lt;/dt&gt;&lt;dt&gt;Pseudo-types used in this  documentation &lt;/dt&gt;&lt;dt&gt;Type  Juggling&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt; &lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.types.intro"&gt;Introduction&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP supports eight primitive types. &lt;/p&gt; &lt;p&gt;Four scalar types:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;boolean&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;integer&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;float&lt;/b&gt;  (floating-point number, aka '&lt;b class="type"&gt;double&lt;/b&gt;') &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;string&lt;/b&gt;  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;Two compound types:   &lt;ul&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;array&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;object&lt;/b&gt;  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;And finally two special types:   &lt;ul&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;resource&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;NULL&lt;/b&gt;  &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;This manual also introduces some pseudo-types for readability reasons:   &lt;ul&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;mixed&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;number&lt;/b&gt; &lt;/p&gt; &lt;/li&gt;&lt;li&gt; &lt;p&gt;&lt;b class="type"&gt;callback&lt;/b&gt; &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;You may also find some references to  the type "double". Consider double the same as float, the two names exist only  for historic reasons.   &lt;p&gt;The type of a variable is usually not set by the programmer; rather, it is  decided at runtime by PHP depending on the context in which that variable is  used. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;If you want to check out the type and value of a certain expression, use &lt;b class="function"&gt;var_dump()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;If you simply want a human-readable representation of the type  for debugging, use &lt;b class="function"&gt;gettype()&lt;/b&gt;. To check for a certain type, do &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;not&lt;/i&gt;&lt;/span&gt; use &lt;b class="function"&gt;gettype()&lt;/b&gt;, but use the  &lt;var class="literal"&gt;is_&lt;var class="replaceable"&gt;type&lt;/var&gt;&lt;/var&gt; functions. Some  examples:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2743"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php&lt;br /&gt;$bool &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;=  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;TRUE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;   &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// a  boolean&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"foo"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// a  string&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;12&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;     &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// an  integer&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;gettype&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bool&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;); &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// prints out "boolean"&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;gettype&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$str&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;);  &lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// prints out "string"&lt;br /&gt;&lt;br /&gt;// If this is an integer,  increment it by four&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;))  {&lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$int &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;+= &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;4&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(255, 128, 0);"&gt;// If  $bool is a string, print it out&lt;br /&gt;// (does not print out  anything)&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;is_string&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$bool&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)) {&lt;br /&gt;    echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"String: $bool"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&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;If you would like to force a variable to be converted to a certain type, you  may either cast the  variable or use the &lt;b class="function"&gt;settype()&lt;/b&gt; function on it. &lt;/p&gt; &lt;p&gt;Note that a variable may be evaluated with different values in certain  situations, depending on what type it is at the time. For more information, see  the section on Type Juggling.  Also, you may be interested in viewing the type  comparison tables, as they show examples of various type related  comparisons. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-2054627258144669620?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/2054627258144669620/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/types.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2054627258144669620'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2054627258144669620'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/types.html' title='Types'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-237608056227706165</id><published>2009-01-08T17:11:00.000-08:00</published><updated>2009-01-08T17:15:14.544-08:00</updated><title type='text'>Basic syntax</title><content type='html'> &lt;div class="chapter"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.basic-syntax.phpmode"&gt;Escaping from  HTML&lt;/a&gt;&lt;/h1&gt;  &lt;div class="sect1"&gt;  &lt;p&gt;When&lt;br /&gt;PHP parses a file, it looks for opening and closing tags, which tell&lt;br /&gt;PHP to start and stop interpreting the code between them. Parsing in&lt;br /&gt;this manner allows php to be embedded in all sorts of different&lt;br /&gt;documents, as everything outside of a pair of opening and closing tags&lt;br /&gt;is ignored by the PHP parser. Most of the time you will see php&lt;br /&gt;embedded in HTML documents, as in this example. &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2622"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;p&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;This is going to be  ignored.&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'While this is  going to be parsed.'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;; &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;p&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;This will also be  ignored.&lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/p&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;You can also use more advanced structures:  &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN2625"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 10-1. Advanced escaping&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;if  (&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;$expression&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;) {&lt;br&gt;    &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;    &lt;strong&gt;This is  true.&lt;/strong&gt;&lt;br&gt;    &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;} else {&lt;br&gt;    &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;    &lt;strong&gt;This is  false.&lt;/strong&gt;&lt;br&gt;    &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;}&lt;br&gt;&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/font&gt;  &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&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;This&lt;br /&gt;works as expected, because when PHP hits the ?&amp;gt; closing tags, it&lt;br /&gt;simply starts outputting whatever it finds until it hits another&lt;br /&gt;opening tag. The example given here is contrived, of course, but for&lt;br /&gt;outputting large blocks of text, dropping out of PHP parsing mode is&lt;br /&gt;generally more efficient than sending all of the text through &lt;b class="function"&gt;echo()&lt;/b&gt; or &lt;b class="function"&gt;print()&lt;/b&gt;. &lt;/p&gt; &lt;p&gt;There are four different pairs of opening and closing tags which can be used  in php. Two of those,  and &lt;script language="php"&gt;  &lt;/script&gt;, are always available. The other two are short tags and &lt;font class="productname"&gt;ASP&lt;/font&gt; style tags, and can be turned on and off from the  &lt;TT class=filename&gt;php.ini&lt;/TT&gt; configuration file. As such, while some people  find short tags and &lt;font class="productname"&gt;ASP&lt;/font&gt; style tags convenient,  they are less portable, and generally not recommended.  &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Also&lt;br /&gt;note that if you are embedding PHP within XML or XHTML you will need to&lt;br /&gt;use the tags to remain compliant with standards. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;  &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN2637"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 10-2. PHP Opening and Closing Tags&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;1.  &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'if  you want to serve XHTML or XML documents, do like this'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;; &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;2.  &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;script language="php"&gt;&lt;br /&gt;        &lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'some editors  (like FrontPage) don\'t&lt;br /&gt;              like processing  instructions'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;    &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;/script&gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;3.  &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo  &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'this is the simplest, an SGML processing  instruction'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;; &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;     This is a shortcut for &amp;quot;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo  &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;expression ?&amp;gt;&lt;/font&gt;&amp;quot;&lt;br&gt;&lt;br&gt;4.  &amp;lt;%  echo 'You may optionally use ASP-style tags'; %&amp;gt;&lt;br&gt;    &amp;lt;%= $variable; #  This is a shortcut for &amp;quot;&amp;lt;% echo . . .&amp;quot; %&amp;gt;&lt;/font&gt;  &lt;/font&gt;&lt;/font&gt;&lt;/font&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;While&lt;br /&gt;the tags seen in examples one and two are both always available,&lt;br /&gt;example one is the most commonly used, and recommended, of the two. &lt;/p&gt; &lt;p&gt;Short tags (example three) are only available when they are enabled via the  short_open_tag &lt;TT class=filename&gt;php.ini&lt;/TT&gt; configuration file directive, or if php was  configured with the &lt;var class="option"&gt;--enable-short-tags&lt;/var&gt; option.  &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;If you are using PHP 3 you may also enable short tags via the &lt;b class="function"&gt;short_tags()&lt;/b&gt; function. &lt;font class="emphasis"&gt;&lt;i class="emphasis"&gt;This is only available in PHP 3!&lt;/i&gt;&lt;/font&gt;  &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;  &lt;p&gt;&lt;font class="productname"&gt;ASP&lt;/font&gt; style tags (example four) are only  available when they are enabled via the asp_tags &lt;TT class=filename&gt;php.ini&lt;/TT&gt;  configuration file directive.  &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Support for &lt;font class="productname"&gt;ASP&lt;/font&gt; tags was added in  3.0.4. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;  &lt;p&gt; &lt;/p&gt;&lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;Using&lt;br /&gt;short tags should be avoided when developing applications or libraries&lt;br /&gt;that are meant for redistribution, or deployment on PHP servers which&lt;br /&gt;are not under your control, because short tags may not be supported on&lt;br /&gt;the target server. For portable, redistributable code, be sure not to&lt;br /&gt;use short tags. &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;/div&gt;&lt;/div&gt;&lt;br&gt;&lt;p&gt;As in C or&lt;br /&gt;Perl, PHP requires instructions to be terminated with a semicolon at&lt;br /&gt;the end of each statement. The closing tag of a block of PHP code&lt;br /&gt;automatically implies a semicolon; you do not need to have a semicolon&lt;br /&gt;terminating the last line of a PHP block. The closing tag for the block&lt;br /&gt;will include the immediately trailing newline if one is present. &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2662"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo  &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'This is a test'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br&gt;&lt;/font&gt;&lt;br&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'This is a test' &lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;The&lt;br /&gt;closing tag of a PHP block at the end of a file is optional, and in&lt;br /&gt;some cases not using it is helpful when using output buffering and &lt;b class="function"&gt;include()&lt;/b&gt; or &lt;b class="function"&gt;require()&lt;/b&gt;.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="language.basic-syntax.comments"&gt;Comments&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. For  example:  &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2671"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo  &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'This is a test'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;; &lt;/font&gt;&lt;font style="color: rgb(255, 128, 0);"&gt;// This is a  one-line c++ style comment&lt;br&gt;    /* This is a multi line comment&lt;br&gt;       yet  another line of comment */&lt;br&gt;    &lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;echo  &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'This is yet another test'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;;&lt;br&gt;    echo &lt;/font&gt;&lt;font style="color: rgb(221, 0, 0);"&gt;'One  Final Test'&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;; &lt;/font&gt;&lt;font style="color: rgb(255, 128, 0);"&gt;# This is a shell-style comment&lt;br&gt;&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;The&lt;br /&gt;&amp;quot;one-line&amp;quot; comment styles only comment to the end of the line or the&lt;br /&gt;current block of PHP code, whichever comes first. This means that HTML&lt;br /&gt;code after &lt;VAR class=literal&gt;// ?&amp;gt;&lt;/VAR&gt; WILL be printed: ?&amp;gt; skips out of the  PHP mode and returns to HTML mode, and &lt;VAR class=literal&gt;//&lt;/VAR&gt; cannot  influence that. If asp_tags  configuration directive is enabled, it behaves the same with &lt;VAR class=literal&gt;// %&amp;gt;&lt;/VAR&gt;. However,   tag doesn't escape PHP mode in one-line comment. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2680"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;h1&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;This is an &lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(255, 128, 0);"&gt;# echo  'simple';&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/font&gt;  example.&lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/h1&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;br&gt;&lt;/font&gt;&lt;/code&gt;&lt;p&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;The header above will say 'This is an  example'.&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;/font&gt; &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;'C' style comments end by the first encountered &lt;VAR class=literal&gt;*/&lt;/VAR&gt;.  You should be careful not to nest 'C' style comments, which can happen when  commenting out large blocks. &lt;/p&gt; &lt;p&gt; &lt;/p&gt;&lt;div class="informalexample"&gt; &lt;a name="AEN2685"&gt;&lt;/a&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;font style="color: rgb(0, 0, 0);"&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;&lt;font style="color: rgb(255, 128, 0);"&gt;/* &lt;br&gt;    echo 'This is a test'; /* This comment will cause a problem  */&lt;br&gt;&lt;/font&gt;&lt;font style="color: rgb(0, 119, 0);"&gt;*/&lt;br&gt;&lt;/font&gt;&lt;font style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/font&gt; &lt;/font&gt;&lt;/font&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt; &lt;/div&gt;&lt;br&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-237608056227706165?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/237608056227706165/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/basic-syntax.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/237608056227706165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/237608056227706165'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/basic-syntax.html' title='Basic syntax'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6518667085441384371</id><published>2009-01-08T17:10:00.004-08:00</published><updated>2009-01-08T17:11:42.439-08:00</updated><title type='text'>Language Reference</title><content type='html'>&lt;h1 class="title"&gt;Language Reference&lt;/h1&gt; &lt;div class="TOC"&gt; &lt;dl&gt;&lt;dt&gt;&lt;b&gt;????&lt;/b&gt; &lt;/dt&gt;&lt;dt&gt;10. Basic syntax &lt;/dt&gt;&lt;dt&gt;11. Types &lt;/dt&gt;&lt;dt&gt;12. Variables &lt;/dt&gt;&lt;dt&gt;13. Constants &lt;/dt&gt;&lt;dt&gt;14. Expressions &lt;/dt&gt;&lt;dt&gt;15. Operators &lt;/dt&gt;&lt;dt&gt;16. Control Structures &lt;/dt&gt;&lt;dt&gt;17. Functions &lt;/dt&gt;&lt;dt&gt;18. Classes and Objects (PHP 4) &lt;/dt&gt;&lt;dt&gt;19. Classes and Objects (PHP 5) &lt;/dt&gt;&lt;dt&gt;20. Exceptions &lt;/dt&gt;&lt;dt&gt;21. References  Explained&lt;/dt&gt;&lt;/dl&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6518667085441384371?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6518667085441384371/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/language-reference.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6518667085441384371'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6518667085441384371'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/language-reference.html' title='Language Reference'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-7622933062773727966</id><published>2009-01-08T17:10:00.003-08:00</published><updated>2009-01-08T17:10:49.099-08:00</updated><title type='text'>Using old code with new versions of PHP</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="tutorial.oldcode"&gt;Using old code with new versions of  PHP&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Now that PHP has grown to be a popular scripting language, there are a lot of  public repositories and libraries containing code you can reuse. The PHP  developers have largely tried to preserve backwards compatibility, so a script  written for an older version will run (ideally) without changes in a newer  version of PHP. In practice, some changes will usually be needed. &lt;/p&gt; &lt;p&gt;Two of the most important recent changes that affect old code are:  &lt;/p&gt; &lt;ul&gt;&lt;li&gt; &lt;p&gt;The deprecation of the old &lt;var class="varname"&gt;$HTTP_*_VARS&lt;/var&gt; arrays  (which need to be indicated as global when used inside a function or method).  The following autoglobal  arrays were introduced in PHP 4.1.0. They are: &lt;var class="varname"&gt;$_GET&lt;/var&gt;, &lt;var class="varname"&gt;$_POST&lt;/var&gt;, &lt;var class="varname"&gt;$_COOKIE&lt;/var&gt;, &lt;var class="varname"&gt;$_SERVER&lt;/var&gt;, &lt;var class="varname"&gt;$_FILES&lt;/var&gt;, &lt;var class="varname"&gt;$_ENV&lt;/var&gt;, &lt;var class="varname"&gt;$_REQUEST&lt;/var&gt;, and &lt;var class="varname"&gt;$_SESSION&lt;/var&gt;. The older &lt;var class="varname"&gt;$HTTP_*_VARS&lt;/var&gt;  arrays, such as &lt;var class="varname"&gt;$HTTP_POST_VARS&lt;/var&gt;, still exist as they  have since PHP 3. 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;/li&gt;&lt;li&gt; &lt;p&gt;External variables are no longer registered in the global scope by default.  In other words, as of PHP 4.2.0 the PHP directive register_globals is &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;off&lt;/i&gt;&lt;/span&gt; by default in &lt;tt class="filename"&gt;php.ini&lt;/tt&gt;. The preferred method of accessing these values is  via the autoglobal arrays mentioned above. Older scripts, books, and tutorials  may rely on this directive being on. If it were on, for example, one could use  &lt;var class="varname"&gt;$id&lt;/var&gt; from the URL &lt;var class="literal"&gt;http://www.example.com/foo.php?id=42&lt;/var&gt;. Whether on or off,  &lt;var class="varname"&gt;$_GET['id']&lt;/var&gt; is available. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;For more  details on these changes, see the section on predefined variables and links  therein.  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-7622933062773727966?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/7622933062773727966/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/using-old-code-with-new-versions-of-php.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7622933062773727966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/7622933062773727966'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/using-old-code-with-new-versions-of-php.html' title='Using old code with new versions of 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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5313210536099107782</id><published>2009-01-08T17:10:00.001-08:00</published><updated>2009-01-08T17:10:24.584-08:00</updated><title type='text'>Dealing with Forms</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="tutorial.forms"&gt;Dealing with Forms&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;One of the most powerful features of PHP is the way it handles HTML forms.  The basic concept that is important to understand is that any form element will  automatically be available to your PHP scripts. Please read the manual section  on Variables from outside of PHP  for more information and examples on using forms with PHP. Here is an example  HTML form: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN283"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 2-6. A simple HTML form&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;&lt;form action="action.php" method="post"&gt;&lt;br /&gt;&lt;p&gt;Your name: &lt;input type="text" name="name"&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Your age: &lt;input type="text" name="age"&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;input type="submit"&gt;&lt;/p&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;There is nothing special about this form. It is a straight HTML form with no  special tags of any kind. When the user fills in this form and hits the submit  button, the &lt;tt class="filename"&gt;action.php&lt;/tt&gt; page is called. In this file you  would write something like this: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN289"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 2-7. Printing data from our form&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Hi &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php  &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'name'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;.&lt;br /&gt;You are &lt;span style="color: rgb(0, 0, 187);"&gt;&lt;?php &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_POST&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'age'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;]; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt; years  old.&lt;/span&gt; &lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;A sample output of this script may be: &lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;Hi Joe. You are 22 years old.&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;It should be obvious what this does. There is nothing more to it. The &lt;var class="varname"&gt;$_POST['name']&lt;/var&gt; and &lt;var class="varname"&gt;$_POST['age']&lt;/var&gt;  variables are automatically set for you by PHP. Earlier we used the &lt;var class="varname"&gt;$_SERVER&lt;/var&gt; autoglobal; above we just introduced the $_POST autoglobal  which contains all POST data. Notice how the &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;method&lt;/i&gt;&lt;/span&gt; of our form is POST. If we used the method  &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;GET&lt;/i&gt;&lt;/span&gt; then our form information  would live in the $_GET autoglobal  instead. You may also use the $_REQUEST  autoglobal, if you do not care about the source of your request data. It  contains the merged information of GET, POST and COOKIE data. Also see the &lt;b class="function"&gt;import_request_variables()&lt;/b&gt; function. &lt;/p&gt; &lt;p&gt;You can also deal with XForms input in PHP, although you will find yourself  comfortable with the well supported HTML forms for quite some time. While  working with XForms is not for beginners, you might be interested in them. We  also have a short introduction to handling data  received from XForms in our features section. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5313210536099107782?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5313210536099107782/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/dealing-with-forms.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5313210536099107782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5313210536099107782'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/dealing-with-forms.html' title='Dealing with Forms'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-5483616790011130454</id><published>2009-01-08T17:09:00.001-08:00</published><updated>2009-01-08T17:09:50.589-08:00</updated><title type='text'>5 . Something Useful</title><content type='html'>&lt;div class="sect1"&gt; &lt;h1 class="sect1"&gt;&lt;a name="tutorial.useful"&gt;Something Useful&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;Let us do something more useful now. We are going to check what sort of  browser the visitor is using. For that, we check the user agent string the  browser sends as part of the HTTP request. This information is stored in a variable. Variables always start with a  dollar-sign in PHP. The variable we are interested in right now is &lt;var class="varname"&gt;$_SERVER['HTTP_USER_AGENT']&lt;/var&gt;. &lt;/p&gt; &lt;div class="note"&gt; &lt;blockquote class="note"&gt; &lt;p&gt;&lt;b&gt;????: &lt;/b&gt;$_SERVER is a  special reserved PHP variable that contains all web server information. It is  known as an autoglobal (or superglobal). See the related manual page on superglobals  for more information. These special variables were introduced in PHP 4.1.0. Before this  time, we used the older &lt;var class="varname"&gt;$HTTP_*_VARS&lt;/var&gt; arrays instead,  such as &lt;var class="varname"&gt;$HTTP_SERVER_VARS&lt;/var&gt;. Although deprecated, these  older variables still exist. (See also the note on old code.) &lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt; &lt;p&gt;To display this variable, you can simply do: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN228"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 2-3. Printing a variable (Array element)&lt;/b&gt;&lt;/p&gt; &lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'HTTP_USER_AGENT'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;];  &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&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;A sample output of this script may be: &lt;/p&gt; &lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)&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;There are many types of variables available  in PHP. In the above example we printed an Array element. Arrays can be very useful.  &lt;/p&gt; &lt;p&gt;&lt;var class="varname"&gt;$_SERVER&lt;/var&gt; is just one variable that PHP automatically  makes available to you. A list can be seen in the Reserved Variables section of the manual or  you can get a complete list of them by looking at the output of the &lt;b class="function"&gt;phpinfo()&lt;/b&gt; function used  in the example in the previous section. &lt;/p&gt; &lt;p&gt;You can put multiple PHP statements inside a PHP tag and create little blocks  of code that do more than just a single echo. For example, if you want to check  for Internet Explorer you can do this: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN242"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 2-4. Example using control structures and functions&lt;/b&gt;&lt;/p&gt; &lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strpos&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'HTTP_USER_AGENT'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;],  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'MSIE'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  !== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;FALSE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;   echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'You  are using Internet Explorer.&lt;br /&gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&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;A sample output of this script may be: &lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;You are using Internet Explorer.&lt;br /&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;Here we introduce a couple of new concepts. We have an if statement.  If you are familiar with the basic syntax used by the C language, this should  look logical to you. Otherwise, you should probably pick up an introductory PHP  book and read the first couple of chapters, or read the Language Reference part of the manual. You can find a  list of PHP books at http://www.php.net/books.php. &lt;/p&gt; &lt;p&gt;The second concept we introduced was the &lt;b class="function"&gt;strpos()&lt;/b&gt; function call. &lt;b class="function"&gt;strpos()&lt;/b&gt; is a function built into PHP which searches a  string for another string. In this case we are looking for &lt;var class="literal"&gt;'MSIE'&lt;/var&gt; (so-called needle) inside &lt;var class="varname"&gt;$_SERVER['HTTP_USER_AGENT']&lt;/var&gt; (so-called haystack). If the  needle is found inside the haystack, the function returns the position of the  needle relative to the start of the haystack. Otherwise, it returns &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;. If it does not return &lt;tt class="constant"&gt;&lt;b&gt;FALSE&lt;/b&gt;&lt;/tt&gt;, the if expression  evaluates to &lt;tt class="constant"&gt;&lt;b&gt;TRUE&lt;/b&gt;&lt;/tt&gt; and the code within its  {braces} is executed. Otherwise, the code is not run. Feel free to create  similar examples, with if, else, and other functions such as &lt;b class="function"&gt;strtoupper()&lt;/b&gt; and &lt;b class="function"&gt;strlen()&lt;/b&gt;. Each related  manual page contains examples too. If you are unsure how to use functions, you  will want to read both the manual page on how to  read a function definition and the section about PHP functions. &lt;/p&gt; &lt;p&gt;We can take this a step further and show how you can jump in and out of PHP  mode even in the middle of a PHP block: &lt;/p&gt; &lt;p&gt; &lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;div class="example"&gt;&lt;a name="AEN270"&gt;&lt;/a&gt; &lt;p&gt;&lt;b&gt;????? 2-5. Mixing both HTML and PHP modes&lt;/b&gt;&lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;if  (&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;strpos&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;$_SERVER&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'HTTP_USER_AGENT'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;],  &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'MSIE'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;)  !== &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;FALSE&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;) {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;h3&gt;strpos() must have returned  non-false&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;You are using Internet  Explorer&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;} else {&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;br /&gt;&lt;/span&gt;&lt;h3&gt;strpos() must have returned  false&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;You are not using Internet  Explorer&lt;/p&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&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;A sample output of this script may be: &lt;/p&gt; &lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;pre class="html"&gt;&lt;h3&gt;strpos() must have returned non-false&lt;/h3&gt;&lt;br /&gt;&lt;p&gt;You are using Internet Explorer&lt;/p&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;Instead of using a PHP echo statement to output something, we jumped out of  PHP mode and just sent straight HTML. The important and powerful point to note  here is that the logical flow of the script remains intact. Only one of the HTML  blocks will end up getting sent to the viewer depending on the result of &lt;b class="function"&gt;strpos()&lt;/b&gt;. In other words,  it depends on whether the string &lt;var class="literal"&gt;MSIE&lt;/var&gt; was found or not.  &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-5483616790011130454?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/5483616790011130454/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/5-something-useful.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5483616790011130454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/5483616790011130454'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/5-something-useful.html' title='5 . Something Useful'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-1347113747692099156</id><published>2009-01-08T17:07:00.001-08:00</published><updated>2009-01-08T17:07:40.760-08:00</updated><title type='text'>4.Your first PHP-enabled page</title><content type='html'>&lt;div class="sect1"&gt;&lt;br /&gt;&lt;h1 class="sect1"&gt;&lt;a name="tutorial.firstpage"&gt;Your first PHP-enabled page&lt;/a&gt;&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;Create a file named &lt;tt class="filename"&gt;hello.php&lt;/tt&gt; and put it in your web&lt;br /&gt;server's root directory (&lt;var class="varname"&gt;DOCUMENT_ROOT&lt;/var&gt;) with the&lt;br /&gt;following content: &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;div class="example"&gt;&lt;a name="AEN174"&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;????? 2-1. Our first PHP script: &lt;tt class="filename"&gt;hello.php&lt;/tt&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;PHP&lt;br /&gt;Test&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;'&amp;lt;p&amp;gt;Hello World&amp;lt;/p&amp;gt;'&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;p&gt;Use your browser to access the file with your web server's URL, ending with&lt;br /&gt;the "/hello.php" file reference. When developing locally this URL will be&lt;br /&gt;something like &lt;var class="literal"&gt;http://localhost/hello.php&lt;/var&gt; or &lt;var class="literal"&gt;http://127.0.0.1/hello.php&lt;/var&gt; but this depends on the web&lt;br /&gt;server's configuration. If everything is configured correctly, this file will be&lt;br /&gt;parsed by PHP and the following output will be sent to your browser: &lt;/p&gt;&lt;br /&gt;&lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;pre class="html"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt; &amp;lt;title&amp;gt;PHP Test&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;Hello World&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;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;This program is extremely simple and you really did not need to use PHP to&lt;br /&gt;create a page like this. All it does is display: &lt;var class="literal"&gt;Hello&lt;br /&gt;World&lt;/var&gt; using the PHP &lt;b class="function"&gt;echo()&lt;/b&gt; statement. Note that the file &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;does not need to be executable&lt;/i&gt;&lt;/span&gt; or&lt;br /&gt;special in any way. The server finds out that this file needs to be interpreted&lt;br /&gt;by PHP because you used the ".php" extension, which the server is configured to&lt;br /&gt;pass on to PHP. Think of this as a normal HTML file which happens to have a set&lt;br /&gt;of special tags available to you that do a lot of interesting things. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;If you tried this example and it did not output anything, it prompted for&lt;br /&gt;download, or you see the whole file as text, chances are that the server you are&lt;br /&gt;on does not have PHP enabled, or is not configured properly. Ask your&lt;br /&gt;administrator to enable it for you using the Installation chapter of the manual. If you are&lt;br /&gt;developing locally, also read the installation chapter to make sure everything&lt;br /&gt;is configured properly. Make sure that you access the file via http with the&lt;br /&gt;server providing you the output. If you just call up the file from your file&lt;br /&gt;system, then it will not be parsed by PHP. If the problems persist anyway, do&lt;br /&gt;not hesitate to use one of the many PHP support options. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The point of the example is to show the special PHP tag format. In this&lt;br /&gt;example we used &lt;var class="literal"&gt;&amp;lt;?php&lt;/var&gt; to indicate the start of a PHP&lt;br /&gt;tag. Then we put the PHP statement and left PHP mode by adding the closing tag,&lt;br /&gt;&lt;var class="literal"&gt;?&amp;gt;&lt;/var&gt;. You may jump in and out of PHP mode in an HTML&lt;br /&gt;file like this anywhere you want. For more details, read the manual section on&lt;br /&gt;the basic PHP syntax. &lt;/p&gt;&lt;br /&gt;&lt;div class="note"&gt;&lt;br /&gt;&lt;blockquote class="note"&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;A Note on Text Editors: &lt;/b&gt;There are many text editors and Integrated&lt;br /&gt;Development Environments (IDEs) that you can use to create, edit and manage PHP&lt;br /&gt;files. A partial list of these tools is maintained at PHP&lt;br /&gt;Editors List. If you wish to recommend an editor, please visit the above&lt;br /&gt;page and ask the page maintainer to add the editor to the list. Having an editor&lt;br /&gt;with syntax highlighting can be helpful. &lt;/p&gt;&lt;p&gt;&lt;b&gt;A Note on Word Processors: &lt;/b&gt;Word processors such as StarOffice Writer,&lt;br /&gt;Microsoft Word and Abiword are not optimal for editing PHP files. If you wish to&lt;br /&gt;use one for this test script, you must ensure that you save the file as &lt;span class="emphasis"&gt;&lt;i class="emphasis"&gt;plain text&lt;/i&gt;&lt;/span&gt; or PHP will not be able&lt;br /&gt;to read and execute the script. &lt;/p&gt;&lt;p&gt;&lt;b&gt;A Note on Windows Notepad: &lt;/b&gt;If you are writing your PHP scripts using&lt;br /&gt;Windows Notepad, you will need to ensure that your files are saved with the .php&lt;br /&gt;extension. (Notepad adds a .txt extension to files automatically unless you take&lt;br /&gt;one of the following steps to prevent it.) When you save the file and are&lt;br /&gt;prompted to provide a name for the file, place the filename in quotes (i.e. "&lt;tt class="filename"&gt;hello.php&lt;/tt&gt;"). Alternatively, you can click on the 'Text&lt;br /&gt;Documents' drop-down menu in the 'Save' dialog box and change the setting to&lt;br /&gt;"All Files". You can then enter your filename without quotes.&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;&lt;p&gt;Now that you have successfully created a working PHP script, it is time to&lt;br /&gt;create the most famous PHP script! Make a call to the &lt;b class="function"&gt;phpinfo()&lt;/b&gt; function and&lt;br /&gt;you will see a lot of useful information about your system and setup such as&lt;br /&gt;available predefined variables,&lt;br /&gt;loaded PHP modules, and configuration settings.&lt;br /&gt;Take some time and review this important information. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;table class="EXAMPLE" border="0" cellpadding="0" cellspacing="0" width="100%"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;div class="example"&gt;&lt;a name="AEN210"&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;????? 2-2. Get system information from PHP&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;table bgcolor="#e0e0e0" border="0" cellpadding="5"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&lt;br /&gt;phpinfo&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;(); &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&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="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-1347113747692099156?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/1347113747692099156/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/4your-first-php-enabled-page.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/1347113747692099156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/1347113747692099156'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/4your-first-php-enabled-page.html' title='4.Your first PHP-enabled page'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-6490679782231675672</id><published>2009-01-08T17:04:00.000-08:00</published><updated>2009-01-08T17:06:06.697-08:00</updated><title type='text'>3. A simple tutorial</title><content type='html'>&lt;p&gt;Here we would like to show the very basics of PHP in a short, simple&lt;br /&gt;tutorial. This text only deals with dynamic webpage creation with PHP, though&lt;br /&gt;PHP is not only capable of creating webpages. See the section titled What can PHP do for more information. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;PHP-enabled web pages are treated just like regular HTML pages and you can&lt;br /&gt;create and edit them the same way you normally create regular HTML pages. &lt;/p&gt;&lt;br /&gt;&lt;div class="sect1"&gt;&lt;br /&gt;&lt;h1 class="sect1"&gt;&lt;a name="tutorial.requirements"&gt;What do I need?&lt;/a&gt;&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;In this tutorial we assume that your server has activated support for PHP and&lt;br /&gt;that all files ending in &lt;tt class="filename"&gt;.php&lt;/tt&gt; are handled by PHP. On&lt;br /&gt;most servers, this is the default extension for PHP files, but ask your server&lt;br /&gt;administrator to be sure. If your server supports PHP, then you do not need to&lt;br /&gt;do anything. Just create your &lt;tt class="filename"&gt;.php&lt;/tt&gt; files, put them in&lt;br /&gt;your web directory and the server will automatically parse them for you. There&lt;br /&gt;is no need to compile anything nor do you need to install any extra tools. Think&lt;br /&gt;of these PHP-enabled files as simple HTML files with a whole new family of&lt;br /&gt;magical tags that let you do all sorts of things. Most web hosts offer PHP&lt;br /&gt;support, but if your host does not, consider reading the PHP Links section for&lt;br /&gt;resources on finding PHP enabled web hosts. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Let us say you want to save precious bandwidth and develop locally. In this&lt;br /&gt;case, you will want to install a web server, such as Apache, and of course PHP. You will most&lt;br /&gt;likely want to install a database as well, such as MySQL. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;You can either install these individually or choose a simpler way. Our manual&lt;br /&gt;has installation instructions for PHP (assuming you&lt;br /&gt;already have some webserver set up). In case you have problems with installing&lt;br /&gt;PHP yourself, we would suggest you ask your questions on our installation mailing&lt;br /&gt;list. If you choose to go on the simpler route, then locate a pre-configured package for your operating system, which&lt;br /&gt;automatically installs all of these with just a few mouse clicks. It is easy to&lt;br /&gt;setup a web server with PHP support on any operating system, including MacOSX,&lt;br /&gt;Linux and Windows. On Linux, you may find rpmfind and PBone helpful for locating RPMs. You may also want to visit apt-get to find packages for&lt;br /&gt;Debian. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-6490679782231675672?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/6490679782231675672/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/3-simple-tutorial.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6490679782231675672'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/6490679782231675672'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/3-simple-tutorial.html' title='3. A simple tutorial'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-3488933538685781803</id><published>2009-01-08T16:58:00.000-08:00</published><updated>2009-01-08T17:00:12.396-08:00</updated><title type='text'>Getting Started -- 2.What can PHP do?</title><content type='html'>&lt;div class="sect1"&gt;&lt;br /&gt;&lt;h1 class="sect1"&gt;&lt;a name="intro-whatcando"&gt;What can PHP do?&lt;/a&gt;&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;Anything. PHP is mainly focused on server-side scripting, so you can do&lt;br /&gt;anything any other CGI program can do, such as collect form data, generate&lt;br /&gt;dynamic page content, or send and receive cookies. But PHP can do much more.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;There are three main areas where PHP scripts are used.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;br /&gt;&lt;p&gt;Server-side scripting. This is the most traditional and main target field for&lt;br /&gt;PHP. You need three things to make this work. The PHP parser (CGI or server&lt;br /&gt;module), a webserver and a web browser. You need to run the webserver, with a&lt;br /&gt;connected PHP installation. You can access the PHP program output with a web&lt;br /&gt;browser, viewing the PHP page through the server. All these can run on your home&lt;br /&gt;machine if you are just experimenting with PHP programming. See the installation instructions section for more information.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;br /&gt;&lt;p&gt;Command line scripting. You can make a PHP script to run it without any&lt;br /&gt;server or browser. You only need the PHP parser to use it this way. This type of&lt;br /&gt;usage is ideal for scripts regularly executed using cron (on *nix or Linux) or&lt;br /&gt;Task Scheduler (on Windows). These scripts can also be used for simple text&lt;br /&gt;processing tasks. See the section about Command line usage of PHP for more&lt;br /&gt;information. &lt;/p&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;&lt;br /&gt;&lt;p&gt;Writing desktop applications. PHP is probably not the very best language to&lt;br /&gt;create a desktop application with a graphical user interface, but if you know&lt;br /&gt;PHP very well, and would like to use some advanced PHP features in your&lt;br /&gt;client-side applications you can also use PHP-GTK to write such programs. You&lt;br /&gt;also have the ability to write cross-platform applications this way. PHP-GTK is&lt;br /&gt;an extension to PHP, not available in the main distribution. If you are&lt;br /&gt;interested in PHP-GTK, visit its own&lt;br /&gt;website. &lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;PHP can be used on all major operating systems, including Linux, many Unix&lt;br /&gt;variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X,&lt;br /&gt;RISC OS, and probably others. PHP has also support for most of the web servers&lt;br /&gt;today. This includes Apache, Microsoft Internet Information Server, Personal Web&lt;br /&gt;Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium,&lt;br /&gt;Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a&lt;br /&gt;module, for the others supporting the CGI standard, PHP can work as a CGI&lt;br /&gt;processor. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;So with PHP, you have the freedom of choosing an operating system and a web&lt;br /&gt;server. Furthermore, you also have the choice of using procedural programming or&lt;br /&gt;object oriented programming, or a mixture of them. Although not every standard&lt;br /&gt;OOP feature is implemented in PHP 4, many code libraries and large applications&lt;br /&gt;(including the PEAR library) are written only using OOP code. PHP 5 fixes the&lt;br /&gt;OOP related weaknesses of PHP 4, and introduces a complete object model. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;With PHP you are not limited to output HTML. PHP's abilities includes&lt;br /&gt;outputting images, PDF files and even Flash movies (using libswf and Ming)&lt;br /&gt;generated on the fly. You can also output easily any text, such as XHTML and any&lt;br /&gt;other XML file. PHP can autogenerate these files, and save them in the file&lt;br /&gt;system, instead of printing it out, forming a server-side cache for your dynamic&lt;br /&gt;content. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;One of the strongest and most significant features in PHP is its support for&lt;br /&gt;a wide range of databases. Writing a database-enabled web page is incredibly&lt;br /&gt;simple. The following databases are currently supported: &lt;a name="AEN115"&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;blockquote class="BLOCKQUOTE"&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="0"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;Adabas D&lt;/td&gt;&lt;br /&gt;&lt;td&gt;InterBase&lt;/td&gt;&lt;br /&gt;&lt;td&gt;PostgreSQL&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;dBase&lt;/td&gt;&lt;br /&gt;&lt;td&gt;FrontBase&lt;/td&gt;&lt;br /&gt;&lt;td&gt;SQLite&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;Empress&lt;/td&gt;&lt;br /&gt;&lt;td&gt;mSQL&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Solid&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;FilePro (read-only)&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Direct MS-SQL&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Sybase&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;Hyperwave&lt;/td&gt;&lt;br /&gt;&lt;td&gt;MySQL&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Velocis&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;IBM DB2&lt;/td&gt;&lt;br /&gt;&lt;td&gt;ODBC&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Unix dbm&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;Informix&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Oracle (OCI7 and OCI8)&lt;/td&gt;&lt;br /&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;Ingres&lt;/td&gt;&lt;br /&gt;&lt;td&gt;Ovrimos&lt;/td&gt;&lt;br /&gt;&lt;td&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;/blockquote&gt;We also have a DBX database abstraction extension allowing&lt;br /&gt;you to transparently use any database supported by that extension. Additionally&lt;br /&gt;PHP supports ODBC, the Open Database Connection standard, so you can connect to&lt;br /&gt;any other database supporting this world standard.&lt;br /&gt;&lt;br /&gt;&lt;p&gt;PHP also has support for talking to other services using protocols such as&lt;br /&gt;LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (on Windows) and countless others. You&lt;br /&gt;can also open raw network sockets and interact using any other protocol. PHP has&lt;br /&gt;support for the WDDX complex data exchange between virtually all Web programming&lt;br /&gt;languages. Talking about interconnection, PHP has support for instantiation of&lt;br /&gt;Java objects and using them transparently as PHP objects. You can also use our&lt;br /&gt;CORBA extension to access remote objects. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;PHP has extremely useful text processing features, from the POSIX Extended or&lt;br /&gt;Perl regular expressions to parsing XML documents. For parsing and accessing XML&lt;br /&gt;documents, PHP 4 supports the SAX and DOM standards, and you can also use the&lt;br /&gt;XSLT extension to transform XML documents. PHP 5 standardizes all the XML&lt;br /&gt;extensions on the solid base of libxml2 and extends the feature set adding&lt;br /&gt;SimpleXML and XMLReader support. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;While using PHP in the e-commerce field, you'll find the Cybercash payment,&lt;br /&gt;CyberMUT, VeriSign Payflow Pro and MCVE functions useful for your online payment&lt;br /&gt;programs. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;At last but not least, we have many other interesting extensions, the&lt;br /&gt;mnoGoSearch search engine functions, the IRC Gateway functions, many compression&lt;br /&gt;utilities (gzip, bz2), calendar conversion, translation... &lt;/p&gt;&lt;br /&gt;&lt;p&gt;As you can see this page is not enough to list all the features and benefits&lt;br /&gt;PHP can offer. Read on in the sections about installing&lt;br /&gt;PHP, and see the function reference part for&lt;br /&gt;explanation of the extensions mentioned here. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-3488933538685781803?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/3488933538685781803/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/getting-started-2what-can-php-do.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3488933538685781803'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/3488933538685781803'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/getting-started-2what-can-php-do.html' title='Getting Started -- 2.What can PHP do?'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1702728768607313896.post-2588657997651488132</id><published>2009-01-08T16:51:00.000-08:00</published><updated>2009-01-08T16:55:52.150-08:00</updated><title type='text'>Getting Started -- 1. Introduction</title><content type='html'>&lt;div class="chapter"&gt;&lt;div class="sect1"&gt;&lt;br /&gt;&lt;h1 class="sect1"&gt;&lt;a name="intro-whatis"&gt;What is PHP?&lt;/a&gt;&lt;/h1&gt;&lt;br /&gt;&lt;p&gt;&lt;acronym class="acronym"&gt;PHP&lt;/acronym&gt; (recursive acronym for "PHP: Hypertext&lt;br /&gt;Preprocessor") is a widely-used Open Source general-purpose scripting language&lt;br /&gt;that is especially suited for Web development and can be embedded into HTML.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Simple answer, but what does that mean? An example: &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;table style="width: 680px; height: 354px;" class="EXAMPLE" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;br /&gt;&lt;div class="example"&gt;&lt;a name="AEN87"&gt;&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;b&gt;????? 1-1. An introductory example&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;&lt;table bg border="0" cellpadding="5" style="color:#e0e0e0;"&gt;&lt;br /&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;br /&gt;&lt;td&gt;&lt;code&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;    &amp;lt;head&amp;gt;&lt;br /&gt;        &amp;lt;title&amp;gt;Example&amp;lt;/title&amp;gt;&lt;br /&gt;    &amp;lt;/head&amp;gt;&lt;br /&gt;    &amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: rgb(0, 0, 187);"&gt;&amp;lt;?php&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;echo &lt;/span&gt;&lt;span style="color: rgb(221, 0, 0);"&gt;"Hi, I'm a PHP&lt;br /&gt;script!"&lt;/span&gt;&lt;span style="color: rgb(0, 119, 0);"&gt;;&lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(0, 0, 187);"&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;    &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;&lt;br /&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;Notice how this is different from a script written in other languages like&lt;br /&gt;Perl or C -- instead of writing a program with lots of commands to output HTML,&lt;br /&gt;you write an HTML script with some embedded code to do something (in this case,&lt;br /&gt;output some text). The PHP code is enclosed in special start and end&lt;br /&gt;tags that allow you to jump into and out of "PHP mode". &lt;/p&gt;&lt;br /&gt;&lt;p&gt;What distinguishes PHP from something like client-side JavaScript is that the&lt;br /&gt;code is executed on the server. If you were to have a script similar to the&lt;br /&gt;above on your server, the client would receive the results of running that&lt;br /&gt;script, with no way of determining what the underlying code may be. You can even&lt;br /&gt;configure your web server to process all your HTML files with PHP, and then&lt;br /&gt;there's really no way that users can tell what you have up your sleeve. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;The best things in using PHP are that it is extremely simple for a newcomer,&lt;br /&gt;but offers many advanced features for a professional programmer. Don't be afraid&lt;br /&gt;reading the long list of PHP's features. You can jump in, in a short time, and&lt;br /&gt;start writing simple scripts in a few hours. &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Although PHP's development is focused on server-side scripting, you can do&lt;br /&gt;much more with it. Read on, and see more in the What can PHP do? section, or go right to the introductory tutorial if you are only interested in web&lt;br /&gt;programming. &lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1702728768607313896-2588657997651488132?l=learnphpscript.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://learnphpscript.blogspot.com/feeds/2588657997651488132/comments/default' title='Publier les commentaires'/><link rel='replies' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/getting-started-1-introduction.html#comment-form' title='0 commentaires'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2588657997651488132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1702728768607313896/posts/default/2588657997651488132'/><link rel='alternate' type='text/html' href='http://learnphpscript.blogspot.com/2009/01/getting-started-1-introduction.html' title='Getting Started -- 1. Introduction'/><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='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
