<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ideawaza.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=122.167.157.25</id>
	<title>IdeaWazaWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://ideawaza.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=122.167.157.25"/>
	<link rel="alternate" type="text/html" href="https://ideawaza.com/wiki/Special:Contributions/122.167.157.25"/>
	<updated>2026-09-29T19:32:31Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.46.0</generator>
	<entry>
		<id>https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Syntax_Overview&amp;diff=42622</id>
		<title>Archive:PHP and MySQL Programming/Syntax Overview</title>
		<link rel="alternate" type="text/html" href="https://ideawaza.com/index.php?title=Archive:PHP_and_MySQL_Programming/Syntax_Overview&amp;diff=42622"/>
		<updated>2008-09-23T11:15:49Z</updated>

		<summary type="html">&lt;p&gt;122.167.157.25: /* PHP tags: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== PHP tags: ==&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;&amp;lt;?php [code] ?&amp;gt;&#039;&#039;&#039; ===&lt;br /&gt;
&lt;br /&gt;
* Enclose php code&lt;br /&gt;
&lt;br /&gt;
* Can be configured in the &amp;lt;code&amp;gt;php.ini&amp;lt;/code&amp;gt; to be &amp;lt;code&amp;gt;&amp;lt;? ?&amp;gt;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;lt;script language=&amp;quot;php&amp;quot;&amp;gt; &amp;lt;/script&amp;gt;&amp;lt;/code&amp;gt; etc.&lt;br /&gt;
&lt;br /&gt;
* Embedded in normal HTML code&lt;br /&gt;
&lt;br /&gt;
* Within php tags, statements are separated by a ; (generally also followed by a new line).&lt;br /&gt;
&lt;br /&gt;
Example: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 print &amp;quot;Hello World\n&amp;quot;;&lt;br /&gt;
 $date = date(&amp;quot;Y-m-d H:i:s&amp;quot;);&lt;br /&gt;
 print &amp;quot;The date and time at the moment is $date&amp;quot;;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &#039;&#039;&#039;&amp;lt;?=&#039;&#039;&#039; ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* Used if you just want to print out the value of a variable&lt;br /&gt;
&lt;br /&gt;
Example:  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $name = &amp;quot;Bobby&amp;quot;;&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;?=$name?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which will output &#039;&#039;Bobby&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;?=date(&amp;quot;Y-m-d H:i:s&amp;quot;)?&amp;gt; &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Which will output something like &#039;&#039;2005-11-09 19:40:05&#039;&#039;.&lt;br /&gt;
[[]]&lt;br /&gt;
&lt;br /&gt;
== Commenting ==&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;#&#039;&#039;&#039;===&lt;br /&gt;
&lt;br /&gt;
* Comments out one line&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 echo &amp;quot;Hello&amp;quot;; # Everything from the hash is commented out&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 # This entire line is commented out&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;//&#039;&#039;&#039;===&lt;br /&gt;
&lt;br /&gt;
* Works just as in Java and JavaScript&lt;br /&gt;
&lt;br /&gt;
* Same function as &#039;&#039;&#039;#&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===&#039;&#039;&#039;/* (text) */&#039;&#039;&#039;===&lt;br /&gt;
&lt;br /&gt;
* Comments out everything between the /* and the */&lt;br /&gt;
&lt;br /&gt;
* Example: &lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 /*All of this is&lt;br /&gt;
 commented out.&lt;br /&gt;
 Even this line!*/&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Variables ==&lt;br /&gt;
&lt;br /&gt;
➢ Variables in PHP are denoted by the $ prefix.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 $a = “Hello World”; # this assigns the string “Hello World” to $a.&lt;br /&gt;
 $b = “$a, I&#039;m Ralfe”; # this assigns “Hello World, I&#039;m Ralfe” to $b.&lt;br /&gt;
 $b = $a.”, I&#039;m Ralfe”; # exactly the same as the previous example.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
➢ PHP supports dynamic variables.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$c = “response”;&lt;br /&gt;
&lt;br /&gt;
$$c = “Hello Ralfe”; # this assigns “Hello Ralfe” to $response.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
➢ PHP variables do not have to be declared ahead of time, nor do they require a type&lt;br /&gt;
definition. PHP handles all data type conversions.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = 4;&lt;br /&gt;
&lt;br /&gt;
$b = 12;&lt;br /&gt;
&lt;br /&gt;
print “The value of a is $a.”; # Uses a as a String.&lt;br /&gt;
&lt;br /&gt;
$c = $a + $b; # $a is now used as an Integer again.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
➢ PHP supports boolean variables, which can be assigned either a one or a zero, or a&lt;br /&gt;
true or false.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = true;&lt;br /&gt;
&lt;br /&gt;
$b = 1;  # $a and $b are the same thing!&lt;br /&gt;
&lt;br /&gt;
$c = false;&lt;br /&gt;
&lt;br /&gt;
$d = 0; # $c and $d are the same thing!&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Operators ==&lt;br /&gt;
&lt;br /&gt;
➢ Arithmetic Operators&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = 4;&lt;br /&gt;
&lt;br /&gt;
$b = 2;&lt;br /&gt;
&lt;br /&gt;
$a + $b = 6;  // Addition&lt;br /&gt;
&lt;br /&gt;
$a - $b = 2;  // Subtraction&lt;br /&gt;
&lt;br /&gt;
$a * $b = 8;  // Multiplication&lt;br /&gt;
&lt;br /&gt;
$a / $b = 2;  // Division&lt;br /&gt;
&lt;br /&gt;
$a % $b = 0;  // Modulus&lt;br /&gt;
&lt;br /&gt;
$a++;  // Increment&lt;br /&gt;
&lt;br /&gt;
$a--;  // Decrement&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
➢ Assignment Operators&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = 4;&lt;br /&gt;
&lt;br /&gt;
$b = $a;&lt;br /&gt;
&lt;br /&gt;
// $b = 4;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
➢ Comparison Operators&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a == $b // test if two values are equal&lt;br /&gt;
&lt;br /&gt;
$a != $b // test if two values are not equal&lt;br /&gt;
&lt;br /&gt;
$a &amp;lt; $b // test if the first value is less than the second&lt;br /&gt;
&lt;br /&gt;
$a &amp;gt; $b // test if the first value is greater than the second&lt;br /&gt;
&lt;br /&gt;
$a &amp;lt;= $b // test if the first value is less than or equal to the second&lt;br /&gt;
&lt;br /&gt;
$a &amp;gt;= $b // test if the first value is greater than or equal to the second&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Concatenation ==&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = &amp;quot;Fill the halls &amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$b = &amp;quot;with poisoned ivy...&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$c = $a . $b;  # the &#039;.&#039; operator concatenates two variables.&lt;br /&gt;
&lt;br /&gt;
// $c = &amp;quot;Fill the halls with poisoned ivy...&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
&lt;br /&gt;
PHP supports both numerically indexed arrays as well as associative arrays.&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
$a = array(1, 2, 3, 4);&lt;br /&gt;
&lt;br /&gt;
// $a[0] = 1;&lt;br /&gt;
&lt;br /&gt;
// $a[1] = 2;&lt;br /&gt;
&lt;br /&gt;
// $a[2] = 3;&lt;br /&gt;
&lt;br /&gt;
// $a[3] = 4;&lt;br /&gt;
&lt;br /&gt;
$b = array(&amp;quot;name&amp;quot; =&amp;gt; &amp;quot;Fred&amp;quot;, &amp;quot;age&amp;quot; =&amp;gt; 30);&lt;br /&gt;
&lt;br /&gt;
// $b[&#039;name&#039;] = &amp;quot;Fred&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
// $b[&#039;age&#039;] = 30;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Decision and Loop Statements ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IF THEN ELSE statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 $a = 1;&lt;br /&gt;
 $b = 10;&lt;br /&gt;
 &lt;br /&gt;
 if ($a &amp;gt; $b) {&lt;br /&gt;
    echo &amp;quot;a is greater than b&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 else if ($a == $b) {&lt;br /&gt;
    echo &amp;quot;a is equal to b&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 else {&lt;br /&gt;
    echo &amp;quot;a is not greater than b&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // a is not greater than b&lt;br /&gt;
&amp;lt;/source&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;SWITCH statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 $a = 100;&lt;br /&gt;
 &lt;br /&gt;
 switch($a) {&lt;br /&gt;
    case(10):&lt;br /&gt;
       echo &amp;quot;The value is 10&amp;quot;;&lt;br /&gt;
       break;&lt;br /&gt;
 &lt;br /&gt;
    case(100):&lt;br /&gt;
       echo &amp;quot;The value is 100&amp;quot;;&lt;br /&gt;
       break;&lt;br /&gt;
 &lt;br /&gt;
    case(1000):&lt;br /&gt;
       echo &amp;quot;The value is 1000&amp;quot;;&lt;br /&gt;
       break;&lt;br /&gt;
 &lt;br /&gt;
    default:&lt;br /&gt;
       echo &amp;quot;Are you sure you entered in a valid number?&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // The value is 100&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;FOR statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 for ($i = 0; $i &amp;lt; 10; $i++) {&lt;br /&gt;
    # initialize $i ; while condition ; increment statement&lt;br /&gt;
    echo $i;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // 0123456789&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;FOREACH statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 $a = array(1, 2, 3, 4, 5);&lt;br /&gt;
 &lt;br /&gt;
 foreach ($a as $val){&lt;br /&gt;
    echo $val;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // 12345&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WHILE statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 while ($row = mysql_fetch_row($result)){&lt;br /&gt;
    print $row[0];&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;DO WHILE statement&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 $i = 0;&lt;br /&gt;
 # Note that it might seem that $i will&lt;br /&gt;
 do{&lt;br /&gt;
    # never be printed to the screen, but&lt;br /&gt;
    print $i;&lt;br /&gt;
    # a DO WHILE loop always executes at&lt;br /&gt;
 } while ($i &amp;gt;0);&lt;br /&gt;
 # least once!&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Functions ==&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 function square_number($number) {&lt;br /&gt;
    return ($number * $number);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 $answer = square_number(10);&lt;br /&gt;
 echo &amp;quot;The answer is {$answer}&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // The answer is 100&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Classes ==&lt;br /&gt;
&lt;br /&gt;
* Example:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
 class dog {&lt;br /&gt;
    var $name;&lt;br /&gt;
    &lt;br /&gt;
    function dog($name){&lt;br /&gt;
       $this-&amp;gt;name = $name;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    function bark(){&lt;br /&gt;
       echo &amp;quot;Woof! Woof!&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    function who_am_i() {&lt;br /&gt;
       echo &amp;quot;My name is {$this-&amp;gt;name}, and I am a dog&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 $the_dog = new dog(&amp;quot;John&amp;quot;);&lt;br /&gt;
 $the_dog-&amp;gt;who_am_i();&lt;br /&gt;
 &lt;br /&gt;
 // OUTPUT:&lt;br /&gt;
 // My name is John, and I am a dog&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[../Introduction to PHP/|Previous: Introduction to PHP]] | [[../|TOC]] | [[../File Handling/|Next: File Handling]]&lt;br /&gt;
&lt;br /&gt;
[[Category:PHP and MySQL Programming|{{SUBPAGENAME}}]]&lt;/div&gt;</summary>
		<author><name>122.167.157.25</name></author>
	</entry>
</feed>