{"id":12616,"date":"2016-06-06T16:15:33","date_gmt":"2016-06-06T13:15:33","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=12616"},"modified":"2018-06-20T16:44:30","modified_gmt":"2018-06-20T13:44:30","slug":"php-tutorial-beginners","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/","title":{"rendered":"PHP Tutorial for Beginners &#8211; The Ultimate Guide"},"content":{"rendered":"<p>PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.<\/p>\n<p>PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. Code is executed in servers, that is why you&#8217;ll have to install a sever-like environment enabled by programs like XAMPP which is an Apache distribution.<\/p>\n<p>[ulp id=&#8217;8njY7i2QRy6sg8pg&#8217;]<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#usage\">1.1 Where is PHP used?<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#why\">1.2 Why PHP?<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#setup\">2. XAMPP Setup<\/a><\/dt>\n<dt><a href=\"#basics\">3. PHP Language Basics<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#escaping-to-php\">3.1 Escaping to PHP<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#commenting-php\">3.2 Commenting PHP<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#hello-php\">3.3 Hello World<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#php-variables\">3.4 Variables in PHP<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#php-conditionals\">3.5 Conditional Statements in PHP<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#php-loops\">3.6 Loops in PHP<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#arrays\">4. PHP Arrays<\/a><\/dt>\n<dt><a href=\"#functions\">5. PHP Functions<\/a><\/dt>\n<dt><a href=\"#db-connect\">6. Connecting to a Database<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#mysql\">6.1 Connecting to MySQL Databases<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#mysqli-procedurial\">6.2 Connecting to MySQLi Databases (Procedurial)<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#mysqli-oo\">6.3 Connecting to MySQLi Databases (Object Oriented)<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#pdo\">6.4 Connecting to PDO Databases<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#forms\">7. PHP Form Handling<\/a><\/dt>\n<dt><a href=\"#include-require\">8. PHP Include &amp; Require Statements<\/a><\/dt>\n<dt><a href=\"#oop\">9. Object Oriented Concepts<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#oop-class\">9.1 PHP Classes<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dd>\n<dl>\n<dt><a href=\"#oop-constructor\">9.2 PHP Constructor Function<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#conclusion\">10. Conclusion<\/a><\/dt>\n<dt><a href=\"#download\">11. Download<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>Back in 1994, Rasmus Lerdorf unleashed the very first version of PHP. However, now the reference implementation is now produced by The PHP Group. The term PHP originally stood for <em>Personal Home Page<\/em> but now it stands for the recursive acronym: <em>Hypertext Preprocessor<\/em>. PHP 4 and PHP 5 are distributed under the <a href=\"http:\/\/php.net\/license\/3_01.txt\" target=\"_blank\" rel=\"noopener\">PHP Licence v3.01<\/a>, which is an <strong>Open Source<\/strong> licence certified by the Open Source Initiative.<\/p>\n<h3><a name=\"usage\"><\/a>1.1 Where is PHP used?<\/h3>\n<p>Three are the main areas where PHP scripts are used:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Server-side scripting<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>This is the most used and main target for PHP. You need three things to make this work the way you need it. The PHP parser (CGI or server module), a web server and a web browser. You need to run the web server where. You can access the PHP program output with a web browser, viewing the PHP page through the server. All these can run on your home machine if you are just experimenting with PHP programming.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Command line scripting<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>You can make a PHP script to run it without any server or browser. You only need the PHP parser to use it this way. This type of usage is ideal for scripts regularly executed using cron (on Linux) or Task Scheduler (on Windows). These scripts can also be used for simple text processing tasks.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Writing desktop applications<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>PHP may not the very best language to create a desktop application with a graphical user interface, but if you know PHP very well, and would like to use some advanced PHP features in your client-side applications you can also use PHP-GTK to write such programs. You also have the ability to write cross-platform applications this way.<\/p>\n<p>In this article, we&#8217;ll have a detailed look at the server-side scripting using PHP.<\/p>\n<h3><a name=\"why\"><\/a>1.2 Why PHP?<\/h3>\n<p>There stand convincing arguments for all those who wonder why PHP is so popular today:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Compatible with almost all servers used nowadays<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A web server is an information technology that processes requests via HTTP, the basic network protocol used to distribute information on the World Wide Web. There exist many types of web servers that servers use. Some of the most important and well-known are: Apache HTTP Server, IIS (Internet Information Services), lighttpd, Sun Java System Web Server etc. As a matter of fact, PHP is compatible with all these web servers and many more.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>PHP will run on most platforms<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Unlike some technologies that require a specific operating system or are built specifically for that, PHP is engineered to run on various platforms like Windows, Mac OSX, Linux, Unix etc)<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>PHP supports such a wide range of databases<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>An important reason why PHP is so used today is also related to the various databases it supports (is compatible with). Some of these databases are: DB++, dBase, Ingres, Mongo, MaxDB, MongoDB, mSQL, Mssql, MySQL, OCI8, PostgreSQL, SQLite, SQLite3 and so on.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>PHP is free to download and open source<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Anyone can start using PHP right now by downloading it from <a href=\"http:\/\/php.net\/\" target=\"_blank\" rel=\"noopener\">php.net<\/a>. Millions of people are using PHP to create dynamic content and database-related applications that make for outstanding web systems. PHP is also open source, which means the original source code is made freely available and may be redistributed and modified.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Easy to learn &amp; large community<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>PHP is a simple language to learn step by step. This makes it easier for people to get engaged in exploring it. It also has such a huge community online that is constantly willing to help you whenever you&#8217;re stuck (which actually happens quite a lot).<\/p>\n<p>The graphic below shows a basic workflow of dynamic content being passed to and from the client using PHP:<\/p>\n<figure id=\"attachment_12630\" aria-describedby=\"caption-attachment-12630\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/dynamic-php.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12630\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/dynamic-php.jpg\" alt=\"PHP Dynamic Content Interaction\" width=\"820\" height=\"500\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/dynamic-php.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/dynamic-php-300x183.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/dynamic-php-768x468.jpg 768w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-12630\" class=\"wp-caption-text\">PHP Dynamic Content Interaction<\/figcaption><\/figure>\n<h2><a name=\"setup\"><\/a>2. XAMPP Setup<\/h2>\n<p>XAMPP is a free and open source cross-platform web server solution developed by Apache Friends, consisting mainly of the Apache HTTP Server, MariaDB database, and interpreters for scripts written in the PHP and Perl programming languages. In order to make your PHP code execute locally, first install XAMPP.<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong><a href=\"https:\/\/www.apachefriends.org\/index.html\" target=\"_blank\" rel=\"noopener\">Download XAMPP<\/a><\/strong><\/li>\n<li><strong>Install the program (check the technologies you want during installation)<\/strong><\/li>\n<li><strong>Open XAMPP and click on &#8220;Start&#8221; on Apache and MySQL (when working with databases)<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<figure id=\"attachment_12658\" aria-describedby=\"caption-attachment-12658\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-installed.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12658\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-installed.jpg\" alt=\"XAMPP window after a successful installation with Apache and MySQL enabled\" width=\"800\" height=\"500\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-installed.jpg 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-installed-300x188.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-installed-768x480.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-12658\" class=\"wp-caption-text\">XAMPP window after a successful installation with Apache and MySQL enabled<\/figcaption><\/figure>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>Place your web project inside the <code>htdocs<\/code> directory. In the common case, if you installed XAMPP directly inside the C: drive of your PC, the path to this folder would be: <code>C:\\xampp\\htdocs<\/code><\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<figure id=\"attachment_12662\" aria-describedby=\"caption-attachment-12662\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-directory.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12662\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-directory.jpg\" alt=\"XAMPP Directory for Web Projects\" width=\"800\" height=\"310\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-directory.jpg 800w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-directory-300x116.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/xampp-directory-768x298.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-12662\" class=\"wp-caption-text\">XAMPP Directory for Web Projects<\/figcaption><\/figure>\n<p>To test the services are up and running you can just enter <strong>localhost<\/strong> in your address bar and expect the welcoming page.<\/p>\n<h2><a name=\"basics\"><\/a>3. PHP Language Basics<\/h2>\n<p>The aim of this section is to introduce the general syntax you should expect in PHP.<\/p>\n<h3><a name=\"escaping-to-php\"><\/a>3.1 Escaping to PHP<\/h3>\n<p>There are four ways the PHP parser engine can differentiate PHP code in a webpage:<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>Canonical PHP Tags<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>This is the most popular and effective PHP tag style and looks like this:<\/p>\n<pre class=\"brush:php\">&lt;?php...?&gt;<\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>Short-open Tags<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>These are the shortest option, but they might need a bit of configuration, and you might either choose the <code>--enable-short-tags<\/code> configuration option when building PHP, or set the <code>short_open_tag<\/code> setting in your php.ini file.<\/p>\n<pre class=\"brush:php\">&lt;?...?&gt;<\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>ASP-like Tags<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>In order to use ASP-like tags, you&#8217;ll need to set the configuration option in the php.ini file:<\/p>\n<pre class=\"brush:php\">&lt;%...%&gt;<\/pre>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li><strong>HTML script Tags<\/strong><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>You can define a new script with an attribute language like so:<\/p>\n<pre class=\"brush:xml\">&lt;script language=\"PHP\"&gt;...&lt;\/script&gt;<\/pre>\n<h3><a name=\"commenting-php\"><\/a>3.2 Commenting PHP<\/h3>\n<p>Just like other languages, there are several ways to comment PHP code. Let&#8217;s have a look at the most useful ones:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Use <code>#<\/code> to write single-line comments<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"brush:php\">    &lt;?\r\n      # this is a comment in PHP, a single line comment\r\n    ?&gt;\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Use <code>\/\/<\/code> to also write single-line comments<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"brush:php\">    &lt;?\r\n      \/\/ this is also a comment in PHP, a single line comment\r\n    ?&gt;\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>Use <code>\/* ... *\/<\/code> to write multi-line comments<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"brush:php\">    &lt;?\r\n      \/*  this is a multi line comment\r\n          Name: Web Code Geeks\r\n          Type: Website\r\n          Purpose: Web Development\r\n      *\/\r\n    ?&gt;\r\n<\/pre>\n<h3><a name=\"hello-php\"><\/a>3.3 Hello World<\/h3>\n<p>The very basic example of outputting a text in PHP would be:<\/p>\n<pre class=\"brush:php\">  &lt;?\r\n      print(\"Hello World\");\r\n      echo \"Hello World\";\r\n      printf(\"Hello World\");\r\n  ?&gt;\r\n<\/pre>\n<p>The result of the above statements would be the same: &#8220;Hello World&#8221;. But why are there three different ways to output?<\/p>\n<ul>\n<li><strong>print<\/strong> returns a value. It always returns 1.<\/li>\n<li><strong>echo<\/strong> can take a comma delimited list of arguments to output.<\/li>\n<li><strong>printf<\/strong> is a direct analog of C&#8217;s <code>printf()<\/code>.<\/li>\n<\/ul>\n<h3><a name=\"php-variables\"><\/a>3.4 Variables in PHP<\/h3>\n<p>Any type of variable in PHP starts with a leading dollar sign ($) and is assigned a variable type using the = (equals) sign. The value of a variable is the value of its most recent assignment. In PHP, variables do not need to be declared before assignment. The main data types used to construct variables are:<\/p>\n<ul>\n<li><strong>Integers<\/strong> &#8211; whole numbers like 23, 1254, 964 etc<\/li>\n<li><strong>Doubles<\/strong> &#8211; floating-point numbers like 46.2, 733.21 etc<\/li>\n<li><strong>Booleans<\/strong> &#8211; only two possible values, true or false<\/li>\n<li><strong>Strings<\/strong> &#8211; set of characters, like &#8216;Web Code Geeks&#8217;<\/li>\n<li><strong>Arrays<\/strong> &#8211; named and indexed collections of other values<\/li>\n<li><strong>Objects<\/strong> &#8211; instances of predefined classes<\/li>\n<\/ul>\n<p>The following snippet shows all of these data types declared as variables:<\/p>\n<pre class=\"brush:php\">    &lt;?\r\n      $intNum = 472;\r\n      $doubleNum = 29.3;\r\n      $boolean = true;\r\n      $string = 'Web Code Geeks';\r\n      $array = array(\"Pineapple\", \"Grapefruit\", \"Banana\");\r\n\r\n      \/\/ creating a class before declaring an object variable\r\n      class person {\r\n        function agePrint() {\r\n            $age = 5;\r\n            echo \"This person is $age years old!\";\r\n        }\r\n      }\r\n      \/\/ creating a new object of type person\r\n      $object = new person;\r\n    ?&gt;\r\n<\/pre>\n<h3><a name=\"php-conditionals\"><\/a>3.5 Conditional Statements in PHP<\/h3>\n<p>Conditional statements are used to execute different code based on different conditions.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>The If statement<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The <strong>if<\/strong> statement executes a piece of code if a condition is true. The syntax is:<\/p>\n<pre class=\"brush:php\">  if (condition) {\r\n    \/\/ code to be executed in case the condition is true\r\n  }\r\n<\/pre>\n<p>A practical example would be:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $age = 18;\r\n\r\n  if ($age &lt; 20) {\r\n    echo \"You are a teenager\";\r\n  }\r\n  ?&gt;\r\n<\/pre>\n<p>Because the condition is true, the result would be:<\/p>\n<pre class=\"brush:bash\">  You are a teenager\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>The If&#8230;Else statement<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The If&#8230;Else statement executed a piece of code if a condition is true and another piece of code if the condition is false. The syntax is:<\/p>\n<pre class=\"brush:php\">  if (condition) {\r\n    \/\/ code to be executed in case the condition is true\r\n  }\r\n  else {\r\n    \/\/ code to be executed in case the condition is false\r\n  }\r\n<\/pre>\n<p>An example of an If&#8230;Else statement would be:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $age = 25;\r\n\r\n  if ($age &lt; 20) {\r\n    echo \"You are a teenager\";\r\n  }\r\n  else {\r\n    echo \"You are an adult\";\r\n  }\r\n  ?&gt;\r\n<\/pre>\n<p>Because the condition is false, the result in this case would be:<\/p>\n<pre class=\"brush:bash\">  You are an adult\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>The If&#8230;Elseif&#8230;Else statement<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>This kind of statement is used to define what should be executed in the case when two or more conditions are present. The syntax of this case would be:<\/p>\n<pre class=\"brush:php\">  if (condition1) {\r\n    \/\/ code to be executed in case condition1 is true\r\n  }\r\n  elseif (condition2) {\r\n    \/\/ code to be executed in case condition2 is true\r\n  }\r\n  else {\r\n    \/\/ code to be executed in case all conditions are false\r\n  }\r\n<\/pre>\n<p>Again, a simple example to demonstrate this:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n$age = 3;\r\n\r\nif ($age &lt; 10) {\r\n  echo \"You are a kid\";\r\n} elseif ($age &lt; 20) {\r\n  echo \"You are a teenager\";\r\n} else {\r\n  echo \"You are an adult\";\r\n}\r\n?&gt;\r\n<\/pre>\n<p>The result, as you might expect, would be:<\/p>\n<pre class=\"brush:bash\">    You are a kid\r\n<\/pre>\n<h3><a name=\"php-loops\"><\/a>3.6 Loops in PHP<\/h3>\n<p>In PHP, just like any other programming language, loops are used to execute the same code block for a specified number of times. Except for the common loop types (for, while, do&#8230;while), PHP also support <code>foreach<\/code> loops, which is not only specific to PHP. Languages like Javascript and C# already use <strong>foreach<\/strong> loops. Let&#8217;s have a closer look at how each of the loop types works.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>The for loop<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The <code>for<\/code> loop is used when the programmer knows in advance how many times the block of code should be executed. This is the most common type of loop encountered in almost every programming language.<\/p>\n<pre class=\"brush:php\">    for (initialization; condition; step){\r\n       \/\/ executable code\r\n    }\r\n<\/pre>\n<p>An example where we use the for loop would be:<\/p>\n<pre class=\"brush:php\">  for ($i=0; $i &lt; 5; $i++) {\r\n      echo \"This is loop number $i \r\n\";\r\n  }\r\n<\/pre>\n<p>The result of this code snippet would be:<\/p>\n<pre class=\"brush:bash\">    This is loop number 0\r\n    This is loop number 1\r\n    This is loop number 2\r\n    This is loop number 3\r\n    This is loop number 4\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>The while loop<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The <code>while<\/code> loop is used when we want to execute a block of code as long as a test expression continues to be true.<\/p>\n<pre class=\"brush:php\">    while (condition){\r\n       \/\/ executable code\r\n    }\r\n<\/pre>\n<p>An example where we use the while loop would be:<\/p>\n<pre class=\"brush:php\">  $i=0; \/\/ initialization\r\n  while ($i &lt; 5) {\r\n      echo \"This is loop number $i \r\n\";\r\n      $i++; \/\/ step\r\n  }\r\n<\/pre>\n<p>The result of this code snippet would be just the same as before:<\/p>\n<pre class=\"brush:bash\">    This is loop number 0\r\n    This is loop number 1\r\n    This is loop number 2\r\n    This is loop number 3\r\n    This is loop number 4\r\n<\/pre>\n<p>To have a clearer idea of the flow of these two loops, look at the graphic below:<\/p>\n<figure id=\"attachment_12730\" aria-describedby=\"caption-attachment-12730\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-loops-2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12730\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-loops-2.jpg\" alt=\"PHP for and while Loops\" width=\"810\" height=\"650\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-loops-2.jpg 810w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-loops-2-300x241.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-loops-2-768x616.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption id=\"caption-attachment-12730\" class=\"wp-caption-text\">PHP for and while Loops<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>The do&#8230;while loop<\/strong><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>The <code>do...while<\/code> loop is used when we want to execute a block of code at least once and then as long as a test expression is true.<\/p>\n<pre class=\"brush:php\">    do {\r\n      \/\/ executable code\r\n    }\r\n    while (condition);\r\n<\/pre>\n<p>An example where we use the do&#8230;while loop would be:<\/p>\n<pre class=\"brush:php\">  $i = 0; \/\/ initialization\r\n  do {\r\n      $i++; \/\/ step\r\n      echo \"This is loop number $i \r\n\";\r\n  }\r\n  while ($i &lt; 5);  \/\/ condition\r\n<\/pre>\n<p>This time the first loop number would be 1, because the first <code>echo<\/code> was executed only after variable incrementation:<\/p>\n<pre class=\"brush:bash\">    This is loop number 1\r\n    This is loop number 2\r\n    This is loop number 3\r\n    This is loop number 4\r\n    This is loop number 5\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li><strong>The foreach loop<\/strong><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>The <code>foreach<\/code> loop is used to loop through arrays, using a logic where for each pass, the array element is considered a <code>value<\/code> and the array pointer is advanced by one, so that the next element can be processed.<\/p>\n<pre class=\"brush:php\">    foreach (array as value) {\r\n      \/\/ executable code\r\n    }\r\n<\/pre>\n<p>An example where we use the foreach loop would be:<\/p>\n<pre class=\"brush:php\">  $var = array('a','b','c','d','e');  \/\/ array declaration\r\n\r\n  foreach ($var as $key) {\r\n      echo \"Element is $key \r\n\";\r\n  }\r\n<\/pre>\n<p>This time the first loop number would be 1, because the first <code>echo<\/code> was executed only after variable incrementation:<\/p>\n<pre class=\"brush:bash\">    Element is a\r\n    Element is b\r\n    Element is c\r\n    Element is d\r\n    Element is e\r\n<\/pre>\n<h2><a name=\"arrays\"><\/a>4. PHP Arrays<\/h2>\n<p>Arrays are used to store multiple values in a single variable. A simple example of an array in PHP would be:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n$languages = array(\"JS\", \"PHP\", \"ASP\", \"Java\");\r\n?&gt;\r\n<\/pre>\n<p>Array elements are accessed like this: <code>$arrayName[positionIndex]<\/code>. For the above example we could access &#8220;PHP&#8221; this way: <code>$languages[1]<\/code>. Position index is 1 because in programming languages the first element is always element 0. So, PHP would be 1 in this case.<\/p>\n<p>There are three types of arrays in PHP:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Indexed Arrays<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>We can create these kind of arrays in two ways shown below:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $names = array(\"Fabio\", \"Klevi\", \"John\");\r\n  ?&gt;\r\n<\/pre>\n<pre class=\"brush:php\">  &lt;?php\r\n  \/\/ this is a rather manual way of doing it\r\n  $names[0] = \"Fabio\";\r\n  $names[1] = \"Klevi\";\r\n  $names[2] = \"John\";\r\n  ?&gt;\r\n<\/pre>\n<p>An example where we print values from the array is:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $names = array(\"Fabio\", \"Klevi\", \"John\");\r\n  echo \"My friends are \" . $names[0] . \", \" . $names[1] . \" and \" . $names[2];\r\n  ?&gt;\r\n<\/pre>\n<pre class=\"brush:bash\">  \/\/ RESULT\r\n  My friends are Fabio, Klevi and John\r\n<\/pre>\n<p>Looping through an indexed array is done like so:<\/p>\n<pre class=\"brush:php\">    &lt;?php\r\n    $names = array(\"Fabio\", \"Klevi\", \"John\");\r\n    $arrayLength = count($names);\r\n\r\n    for($i = 0; $i &lt; $arrayLength; $i++) {\r\n        echo $names[$i];\r\n        echo \"\r\n\";\r\n    }\r\n  ?&gt;\r\n<\/pre>\n<p>This would just print the values of the array.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Associative Arrays<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Associative arrays are arrays which use named keys that you assign. Again, there are two ways we can create them:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $namesAge = array(\"Fabio\"=&gt;\"20\", \"Klevi\"=&gt;\"16\", \"John\"=&gt;\"43\");\r\n  ?&gt;\r\n<\/pre>\n<pre class=\"brush:php\">  &lt;?php\r\n  \/\/ this is a rather manual way of doing it\r\n  $namesAge['Fabio'] = \"20\";\r\n  $namesAge['Klevi'] = \"18\";\r\n  $namesAge['John'] = \"43\";\r\n  ?&gt;\r\n<\/pre>\n<p>An example where we print values from the array is:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  $namesAge = array(\"Fabio\"=&gt;\"20\", \"Klevi\"=&gt;\"16\", \"John\"=&gt;\"43\");\r\n  echo \"Fabio's age is \" . $namesAge['Fabio'] . \" years old.\";\r\n  ?&gt;\r\n<\/pre>\n<pre class=\"brush:bash\">  \/\/ RESULT\r\n  Fabio's age is 20 years old.\r\n<\/pre>\n<p>Looping through an associative array is done like so:<\/p>\n<pre class=\"brush:php\">    &lt;?php\r\n    $namesAge = array(\"Fabio\"=&gt;\"20\", \"Klevi\"=&gt;\"16\", \"John\"=&gt;\"43\");\r\n\r\n    foreach($namesAge as $i =&gt; $value) {\r\n        echo \"Key = \" . $i . \", Value = \" . $value;\r\n        echo \"\r\n\";\r\n    }\r\n  ?&gt;\r\n<\/pre>\n<pre class=\"brush:bash\">  Key = Fabio, Value = 20\r\n  Key = Klevi, Value = 16\r\n  Key = John, Value = 43\r\n<\/pre>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Multidimensional Arrays<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>This is a rather advanced PHP stuff, but for the sake of this tutorial, just understand what a multidimensional array is. Basically, it is an arrays the elements of which are other arrays. For example, a three-dimensional array is an array of arrays of arrays. An example of this kind of array would be:<\/p>\n<pre class=\"brush:php\">    &lt;?php\r\n    $socialNetowrks = array (\r\n    array(\"Facebook\", \"feb\", 21),\r\n    array(\"Twitter\",\"dec\", 2),\r\n    array(\"Instagram\",\"aug\", 15));\r\n    ?&gt;\r\n<\/pre>\n<h2><a name=\"functions\"><\/a>5. PHP Functions<\/h2>\n<p>Functions are a type of procedure or routine that gets executed whenever some other code block calls it. PHP has over 1000 built-in functions. These functions help developers avoid redundant work and focus more on the logic rather than routine things. Apart from its own functions, PHP also let&#8217;s you create your own functions. The basic syntax of a function that we create is:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nfunction functionName($argument1, $argument2...) {\r\n  \/\/ code to be executed\r\n}\r\n\r\nfunctionName($argument1, $argument2...); \/\/ function call\r\n?&gt;\r\n<\/pre>\n<p>Every function needs a name, optionally has one or more arguments and most importantly, defines some kind of procedure to be followed within the body, that is, code to be executed. Let&#8217;s see some basic functions:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nfunction showGreeting() { \/\/ function definition\r\n  echo \"Hello Chloe!\";    \/\/ what this function does\r\n}\r\n\r\nshowGreeting(); \/\/ function call\r\n?&gt;\r\n<\/pre>\n<p>This function would just print the message we wrote:<\/p>\n<pre class=\"brush:bash\">Hello Chloe!\r\n<\/pre>\n<p>Another example would be a function with arguments:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nfunction greetPerson($name) { \/\/ function definition with arguments\r\n  echo \"Hi there, \".$name;    \/\/ what this function does\r\n}\r\n\r\ngreetPerson(\"Fabio\"); \/\/ function call\r\ngreetPerson(\"Michael\");\r\n?&gt;\r\n<\/pre>\n<p>This time we&#8217;d have:<\/p>\n<pre class=\"brush:bash\">Hi there, Fabio\r\nHi there, Michael\r\n<\/pre>\n<p>More than one argument can be used whenever needed:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nfunction personProfile($name, $city, $job) { \/\/ function definition with arguments\r\n  echo \"This person is \".$name.\" from \".$city.\".\";\r\n  echo \"\r\n\";\r\n  echo \"His\/Her job is \".$job.\".\";\r\n}\r\n\r\npersonProfile(\"Fabio\", \"Tirana\", \"Web Dev\");\r\necho \"\r\n\";\r\npersonProfile(\"Michael\", \"Athens\", \"Graphic Designer\");\r\necho \"\r\n\";\r\npersonProfile(\"Xena\", \"London\", \"Tailor\");\r\n?&gt;\r\n<\/pre>\n<p>The result would include the printed message together with the arguments:<\/p>\n<pre class=\"brush:bash\">This person is Fabio from Tirana.\r\nHis\/Her job is Web Dev.\r\nThis person is Michael from Athens.\r\nHis\/Her job is Graphic Designer.\r\nThis person is Xena from London.\r\nHis\/Her job is Tailor.\r\n<\/pre>\n<p>In PHP, just like in many other languages, we can tell functions to return a value upon executing the code. Such example would be:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nfunction difference($a, $b) { \/\/ function definition with arguments\r\n  $c = $a - $b;\r\n  return $c;\r\n}\r\n\r\necho \"The difference of the given numbers is: \".difference(8, 3);\r\n?&gt;\r\n<\/pre>\n<p>The result would be:<\/p>\n<pre class=\"brush:bash\">The difference of the given numbers is: 5\r\n<\/pre>\n<p>PHP also provides quite useful functions for developers to use. One of them is the <code>mail()<\/code> function. Have a detailed look of how you can use this function to send e-mails <a href=\"https:\/\/www.webcodegeeks.com\/php\/php-mail-function-example\/\"><strong>in this article<\/strong><\/a><\/p>\n<h2><a name=\"db-connect\"><\/a>6. Connecting to a Database<\/h2>\n<p>There are four ways you can generally consider when you want to connect to a previously created database. Below, we&#8217;ll explain how you can use each of them beginning with the easiest one.<\/p>\n<h3><a name=\"mysql\"><\/a>6.1 Connecting to MySQL Databases<\/h3>\n<p>The syntax for connecting to a MySQL database would be:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n$username = \"your_name\";\r\n$password = \"your_password\";\r\n$hostname = \"localhost\";\r\n\r\n\/\/connection to the database\r\n$dbConnect = mysql_connect($hostname, $username, $password)\r\nor die(\"Unable to connect to MySQL\");\r\necho \"Connected to MySQL\";\r\n\r\n\/\/select a specific database\r\n$dbSelect = mysql_select_db(\"dbName\", $dbConnect)\r\nor die(\"Could not select dbName\");\r\n?&gt;\r\n<\/pre>\n<p>Considering your entered information is correct, you&#8217;d be successfully connected to the right database and ready to start writing and test your queries. Else, the respective error message would appear as defined by the <code>die<\/code> function. However, do keep in mind that the mysql extension is deprecated and will be removed in the future, so the next methods can be used for databases.<\/p>\n<h3><a name=\"mysqli-procedurial\"><\/a>6.2 Connecting to MySQLi Databases (Procedurial)<\/h3>\n<p>The MySQLi stands for MySQL improved. The syntax for connecting to a database using MySQLi extension is:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\n$username = \"your_name\";\r\n$password = \"your_password\";\r\n$hostname = \"localhost\";\r\n\r\n\/\/connection to the database\r\n$dbConnect = mysqli_connect($hostname, $username, $password)\r\n\r\n\/\/ another way of checking if the connection was successful\r\nif (!$dbConnect) {\r\n  die (\"Connection failed: \" . mysqli_connect_error());\r\n}\r\necho \"Connected successfully\";\r\n\r\n\/\/select a specific database\r\nmysqli_select_db($dbConnect, \"dbName\")\r\n?&gt;\r\n<\/pre>\n<p>This is a good way to start, because it is easy to understand and gets the job done. However, object oriented logic that we&#8217;ll see below is what everyone should be getting into because of the other components of programming being used in this paradigm and also because it is kind of more structured way of doing things.<\/p>\n<h3><a name=\"mysqli-oo\"><\/a>6.3 Connecting to MySQLi databases (Object-Oriented)<\/h3>\n<p>Although the functionality is basically the same, this is another way, the object-oriented way of connecting to a database using the MySQLi extension.<\/p>\n<pre class=\"brush:php\">$username = \"your_name\";\r\n$password = \"your_password\";\r\n$hostname = \"localhost\";\r\n\r\n\/\/ create connection\r\n$dbConnect = new mysqli($hostname, $username, $password);\r\n\r\n\/\/ check connection\r\nif ($dbConnect-&gt;connect_error) {\r\n    die(\"Connection failed: \" . $dbConnect-&gt;connect_error);\r\n}\r\necho \"Connected successfully\";\r\n\r\n\/\/ select a specific database\r\n$mysqli-&gt;select_db(\"dbName\");\r\n<\/pre>\n<p>Even in this case, you can check to see if the database was successfully selected, but it is a matter of choice. Object-Oriented MySQLi is not a different MySQLi as far as code functionality is concerned, but rather a different way\/logic of writing it.<\/p>\n<h3><a name=\"pdo\"><\/a>6.4 Connecting to PDO Databases<\/h3>\n<p>PDO stands for <strong>PHP Data Objects<\/strong> and is a consistent way to access databases, which promises much easier portable code. PDO is more like a data access layer which uses a unified API rather than an abstraction layer. The syntax for connecting to a database using PDO is:<\/p>\n<pre class=\"brush:php\">$username = \"your_name\";\r\n$password = \"your_password\";\r\n$hostname = \"localhost\";\r\n\r\n\/\/ try to create connection\r\ntry {\r\n    $dbConnect = new PDO(\"mysql:host=$hostname;dbname=myDB\", $username, $password);\r\n    \/\/ set the PDO error mode to exception\r\n    $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n    echo \"Connected successfully\";\r\n}\r\n\/\/ show an error if the connection was unsuccessful\r\ncatch(PDOException $e) {\r\n    echo \"Connection failed: \" . $e-&gt;getMessage();\r\n}\r\n<\/pre>\n<p>PDO is widely used today for a bunch of advantages it offers. Among them, we can mention that PDO allows for prepared statements and rollback functionality which makes it really consistent, it throws catchable exceptions which means better error handling and uses blind parameters in statements which increases security.<\/p>\n<h2><a name=\"forms\"><\/a>7. PHP Form Handling<\/h2>\n<p>In HTML, forms are used to collect user input\/information. But, as far as HTML goes, it just provides the graphical interface and the ability to write on the input fields. However, the aim we collect user information is because we need to process this information. That usually means saving the inputs to a database so that they can be accessed later for several purposes. In this section, we will not send information to the database, as that requires an active database that is already set up and includes knowledge form SQL language, but we can retrieve information that the user has given us. That being said, it is important to have a way to get information, becuase what you use it for and where you want to show\/save it depends. Let&#8217;s have a look at the HTML form below:<\/p>\n<pre class=\"brush:xml\">&lt;form method=\"POST\" action=\"wcg.php\"&gt;\r\n    &lt;p&gt;&lt;input type=\"text\" name=\"name\" placeholder=\"Name\"&gt;&lt;\/p&gt;\r\n    &lt;p&gt;&lt;input type=\"email\" name=\"email\" placeholder=\"E-Mail\"&gt;&lt;\/p&gt;\r\n    &lt;p&gt;&lt;input type=\"number\" name=\"age\" placeholder=\"Age\"&gt;&lt;\/p&gt;\r\n    &lt;input type=\"radio\" name=\"gender\" value=\"Male\"&gt; Male\r\n    &lt;input type=\"radio\" name=\"gender\" value=\"Female\"&gt; Female\r\n    &lt;p&gt;&lt;input type=\"submit\" name=\"submit\" value=\"Submit\"&gt;&lt;\/p&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p>This form is just a regular one, and includes inputs for name, e-mail, age and gender. This information will be subject of a <strong>print<\/strong> when the Submit button is clicked. That just proves that we got the information from the user. For now, let&#8217;s see what we got and fill the form:<\/p>\n<figure id=\"attachment_12818\" aria-describedby=\"caption-attachment-12818\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-form-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12818\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-form-1.jpg\" alt=\"HTML form we just created\" width=\"810\" height=\"408\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-form-1.jpg 810w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-form-1-300x151.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-form-1-768x387.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption id=\"caption-attachment-12818\" class=\"wp-caption-text\">HTML form we just created<\/figcaption><\/figure>\n<p>Next, we check each input to make sure the user has written\/chosen something, and the input is not empty. We do this using two well-known functions in PHP, the <code>isset()<\/code> and <code>empty()<\/code>. After making sure we have this right, we can also validate fields. In this case, only the name input may need some sort of validation to make sure one simply doesn&#8217;t write numbers in there, while other inputs are more or less validated from HTML5, in the case of email and age.<\/p>\n<pre class=\"brush:php\">&lt;?php\r\nif (isset($_POST[\"name\"]) &amp;&amp; !empty($_POST[\"name\"])) {\r\n    $name = $_POST[\"name\"];\r\n    if (!preg_match(\"\/^[a-zA-Z ]*$\/\",$name))\r\n    echo \"Name: Only letters and whitespace allowed \r\n\";\r\n    else\r\n    echo \"Name: \".$_POST[\"name\"].\"\r\n\";\r\n}\r\nif (isset($_POST[\"email\"]) &amp;&amp; !empty($_POST[\"email\"])) {\r\n    echo \"E-Mail: \".$_POST[\"email\"].\"\r\n\";\r\n}\r\nif (isset($_POST[\"age\"]) &amp;&amp;!empty($_POST[\"age\"])) {\r\n    echo \"Age: \".$_POST[\"age\"].\"\r\n\";\r\n}\r\nif (isset($_POST[\"gender\"]) &amp;&amp; !empty($_POST[\"gender\"])) {\r\n    echo \"Gender: \".$_POST[\"gender\"];\r\n}\r\n?&gt;\r\n<\/pre>\n<p>Validation is a must for all fields when considering real web projects. We recommend having a closer look to our article on <a href=\"https:\/\/www.webcodegeeks.com\/php\/php-form-validation-example\/\"><strong>PHP Form Validation Example<\/strong><\/a><\/p>\n<p>If the fields have been set, information about each field will be printed. After clicking the &#8220;Submit&#8221; button, the result we&#8217;d have is:<\/p>\n<pre class=\"brush:bash\">Name: Alex Brown\r\nE-Mail: alex.brown@gmail.com\r\nAge: 28\r\nGender: Male\r\n<\/pre>\n<p>As you may have noticed by now, we used this <code>$_POST[\"name\"]<\/code> to get information the user posted.<\/p>\n<p>What about implementing a login form in PHP? Have a look at our <a href=\"https:\/\/www.webcodegeeks.com\/php\/login-form-php-example\/\"><strong>Login Form in PHP Example<\/strong><\/a>.<\/p>\n<h2><a name=\"include-require\"><\/a>8. PHP Include &amp; Require Statements<\/h2>\n<p>PHP code can get cluttered, which means that if you want to later change something, it becomes a hard task to do. Include and require statements are two almost identical statements that help in an important aspect of coding, the organization of code, and making it more readable and flexible. The include\/require statement copies all text, code or any other markup from one existing file to the file using the statement. In a simple viewpoint, do consider these statements like this:<\/p>\n<figure id=\"attachment_12856\" aria-describedby=\"caption-attachment-12856\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/include-php-1.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12856\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/include-php-1.jpg\" alt=\"PHP Include Statement\" width=\"810\" height=\"588\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/include-php-1.jpg 810w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/include-php-1-300x218.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/include-php-1-768x558.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption id=\"caption-attachment-12856\" class=\"wp-caption-text\">PHP Include Statement<\/figcaption><\/figure>\n<p>The include and require statements are the same, except upon failure of code execution where:<\/p>\n<ul>\n<li><strong>require<\/strong> will produce a fatal error (E_COMPILE_ERROR) and stop the script from executing<\/li>\n<li><strong>include<\/strong> will only produce a warning (E_WARNING) and the script will continue<\/li>\n<\/ul>\n<p>The syntax of these two statements is as follows:<\/p>\n<pre class=\"brush:php\">&lt;?php\r\ninclude 'file.php'; \/\/ in case of include\r\nrequire 'file.php'; \/\/ in case of require\r\n?&gt;\r\n<\/pre>\n<p>Let&#8217;s now see a real-world example where we use a header and footer using include and require into our main file:<\/p>\n<p><em>header.php<\/em><\/p>\n<pre class=\"brush:php\">&lt;header&gt;\r\n&lt;nav&gt;\r\n    &lt;ul&gt;\r\n        &lt;li&gt;&lt;a href=\"#\"&gt;Home&lt;\/a&gt;&lt;\/li&gt;\r\n        &lt;li&gt;&lt;a href=\"#\"&gt;Profile&lt;\/a&gt;&lt;\/li&gt;\r\n        &lt;li&gt;&lt;a href=\"#\"&gt;About&lt;\/a&gt;&lt;\/li&gt;\r\n        &lt;li&gt;&lt;a href=\"#\"&gt;Contact&lt;\/a&gt;&lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n&lt;\/nav&gt;\r\n&lt;\/header&gt;\r\n\/\/ styling to make the menu look right\r\n&lt;style type=\"text\/css\"&gt;\r\n    ul, li {\r\n        list-style-type: none;\r\n        display: inline-block;\r\n        margin-right: 1em;\r\n        padding: 0;\r\n    }\r\n&lt;\/style&gt;\r\n<\/pre>\n<p><em>footer.php<\/em><\/p>\n<pre class=\"brush:php\"><\/pre>\n<footer>All Rights Reserved. Do not reproduce this page.\u00a0<\/footer>\n<p>In our main file, we&#8217;ll use <code>require<\/code> for the header.php and <code>include<\/code> for the footer.php file:<\/p>\n<p><em>index.php<\/em><\/p>\n<pre class=\"brush:php\">&lt;?php require 'header.php'; ?&gt;\r\n\r\n&lt;body&gt;\r\n    &lt;h2&gt;Main Content Goes Here&lt;\/h2&gt;\r\n&lt;\/body&gt;\r\n\r\n&lt;?php include 'footer.php' ?&gt;\r\n<\/pre>\n<p>The result, as you might have an idea by now, would be the whole code being shown as one:<\/p>\n<figure id=\"attachment_12859\" aria-describedby=\"caption-attachment-12859\" style=\"width: 810px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-include-require-result.jpg\"><img decoding=\"async\" class=\"size-full wp-image-12859\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-include-require-result.jpg\" alt=\"The result of using include and require in our main file\" width=\"810\" height=\"178\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-include-require-result.jpg 810w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-include-require-result-300x66.jpg 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/php-include-require-result-768x169.jpg 768w\" sizes=\"(max-width: 810px) 100vw, 810px\" \/><\/a><figcaption id=\"caption-attachment-12859\" class=\"wp-caption-text\">The result of using include and require in our main file<\/figcaption><\/figure>\n<h2><a name=\"oop\"><\/a>9. Object Oriented Concepts<\/h2>\n<p>Object oriented programming is a programming language model in the center of which are objects. Let&#8217;s see some of the core concepts of classes and objects before we see actual examples of them:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Class<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A class is a predefined (by a programmer) data type, part of which are local data like variables, functions etc.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Object<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>An object is an instance of a class. Objects can only be created after a class has been define. A programmer can create several objects.<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>Constructor<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>A constructor refers to the concept where all data and member functions are encapsulated to form an object. A destructor, on the other hand, is called automatically whenever an object is deleted or goes out of scope.<\/p>\n<h3><a name=\"oop-class\"><\/a>9.1 PHP Classes<\/h3>\n<p>Let&#8217;s now define a new clas in PHP.<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  class myClass {         \/\/ use 'class' followed by the name of the class\r\n    var $var1;            \/\/ declared an undefined variable\r\n    var $var2 = 5;        \/\/ declared a number defined variable\r\n    var $var3 = \"string\"; \/\/ declared a string defined variable\r\n\r\n    function myFunction ($argument1, $argument2) {  \/\/ function definition\r\n      \/\/ function code here\r\n    }\r\n  }\r\n  ?&gt;\r\n<\/pre>\n<p>But that is just how the syntax looks like. Below, we give an example of a real-world class, for example class <code>Vehicle<\/code>:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  class Vehicle {\r\n    var $brand;       \/\/ just a declared undefined variable\r\n    var $speed = 80;  \/\/ a declared and defined variable\r\n\r\n    function setSpeed($speedValue) {  \/\/ a function to change speed\r\n      $this-&gt;speed = $speedValue;     \/\/ this will replace speed with our value\r\n    }\r\n\r\n    function setBrand($brandName) {   \/\/ a function to change brand\r\n        $this-&gt;brand = $brandName;    \/\/ this will set a brand name\r\n    }\r\n\r\n    function printDetails(){          \/\/ a function to print details\r\n        echo \"Vehicle brand is: \".$this-&gt;brand;\r\n        echo \"\r\n\";\r\n        echo \"Vehicle speed is: \".$this-&gt;speed;\r\n    }\r\n  }\r\n\r\n  $myCar = new Vehicle;       \/\/ an instance of our Vehicle class (an object)\r\n  $myCar-&gt;setBrand(\"Audi\");   \/\/ calling the function setBrand to define a brand\r\n  $myCar-&gt;setSpeed(120);      \/\/ calling the function setSpeed to change speed\r\n  $myCar-&gt;printDetails();     \/\/ calling the printDetails function to see details\r\n  ?&gt;\r\n<\/pre>\n<p>The result of this code would be:<\/p>\n<pre class=\"brush:bash\">Vehicle brand is: Audi\r\nVehicle speed is: 120\r\n<\/pre>\n<p>As you can see, the speed is changed to the latest value set by us.<\/p>\n<h3><a name=\"oop-constructor\"><\/a>9.2 PHP Constructor Function<\/h3>\n<p>PHP provides a special function called <code>__construct()<\/code> to define a constructor, which can take as many arguments as we want. Constructors are called automatically whenever an object is created. Let&#8217;s see how we adopt this into our previously created class. The following code snipper is found inside the class:<\/p>\n<pre class=\"brush:php\">  &lt;?php\r\n  class Vehicle {\r\n  function __construct ($brandName, $speedValue) {\r\n    $this-&gt;brand = $brandName;  \/\/ initialize brand\r\n    $this-&gt;speed = $speedValue; \/\/ initialize speed\r\n    }\r\n      function printDetails(){\r\n          echo \"Vehicle brand is: \".$this-&gt;brand;\r\n          echo \"\r\n\";\r\n          echo \"Vehicle speed is: \".$this-&gt;speed;\r\n          echo \"\r\n\r\n\";\r\n      }\r\n  }\r\n\r\n    $car1 = new Vehicle(\"Toyota\", 130);\r\n    $car2 = new Vehicle (\"Ferrari\", 450);\r\n\r\n    $car1-&gt;printDetails();\r\n    $car2-&gt;printDetails();\r\n  ?&gt;\r\n<\/pre>\n<p>The result now is:<\/p>\n<pre class=\"brush:bash\">Vehicle brand is: Toyota\r\nVehicle speed is: 130\r\n\r\nVehicle brand is: Ferrari\r\nVehicle speed is: 450\r\n<\/pre>\n<p>PHP contains such object oriented rules just like other languages like Java, and as you go on learning it in further details, you&#8217;ll see that you can do more with those variables we declare inside a class, you can set scope to them so that they can only be accessed within a class, a function etc. Also, other concepts like methods overriding is normal when using PHP, as declaring the same method for the second time but with different arguments or code logic, will make the program execute only the latest method it finds in the file.<\/p>\n<h2><a name=\"conclusion\"><\/a>10. Conclusion<\/h2>\n<p>PHP is the fundamental back-end development technology regarding usage and learning curve. It combines such features that make for interactive web pages that people love to use everyday. In this article, we detailed the basic concepts to give you a clear idea of how it can be used in different aspects and information that you might as well relate to other programming languages like loops and conditionals, as most languages recognize these concepts and make use of them.<\/p>\n<p>In the early days, everyone used PHP in a rather procedurial style, as a way to get things done when you don&#8217;t know a lot, but as you learn more and more, you&#8217;ll love working with object-oriented PHP which will make your programming life way much easier and sustainable in big projects. It is important to understand that there are many ways pages could be made dynamic in PHP, and different developers might as well have a totally distinct code that does the same task, that is some kind of flexibility that you get to decide how you are going to implement certain functions (randomly called procedures in PHP). So, just give it a try, you have nothing to lose.<\/p>\n<h2><a name=\"download\"><\/a>11. Download<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here:\u00a0<strong><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2016\/05\/PHP-Tutorial-Samples.zip\">PHP-Tutorial-Samples<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications. PHP is mainly focused on &hellip;<\/p>\n","protected":false},"author":75,"featured_media":930,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-12616","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/fabiocimo\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-06T13:15:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-20T13:44:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fabio Cimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fabiocimo\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fabio Cimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"26 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\"},\"author\":{\"name\":\"Fabio Cimo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\"},\"headline\":\"PHP Tutorial for Beginners &#8211; The Ultimate Guide\",\"datePublished\":\"2016-06-06T13:15:33+00:00\",\"dateModified\":\"2018-06-20T13:44:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\"},\"wordCount\":3745,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\",\"name\":\"PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"datePublished\":\"2016-06-06T13:15:33+00:00\",\"dateModified\":\"2018-06-20T13:44:30+00:00\",\"description\":\"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/php\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PHP Tutorial for Beginners &#8211; The Ultimate Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\",\"name\":\"Fabio Cimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"caption\":\"Fabio Cimo\"},\"description\":\"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.\",\"sameAs\":[\"https:\/\/www.facebook.com\/fabiocimo\",\"https:\/\/al.linkedin.com\/in\/fabiocimo\",\"https:\/\/x.com\/fabiocimo\",\"https:\/\/www.youtube.com\/fabiocimo1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026","description":"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/","og_locale":"en_US","og_type":"article","og_title":"PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026","og_description":"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!","og_url":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/fabiocimo","article_published_time":"2016-06-06T13:15:33+00:00","article_modified_time":"2018-06-20T13:44:30+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","type":"image\/jpeg"}],"author":"Fabio Cimo","twitter_card":"summary_large_image","twitter_creator":"@fabiocimo","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Fabio Cimo","Est. reading time":"26 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/"},"author":{"name":"Fabio Cimo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22"},"headline":"PHP Tutorial for Beginners &#8211; The Ultimate Guide","datePublished":"2016-06-06T13:15:33+00:00","dateModified":"2018-06-20T13:44:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/"},"wordCount":3745,"commentCount":5,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","articleSection":["PHP"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/","url":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/","name":"PHP Tutorial for Beginners - The Ultimate Guide - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","datePublished":"2016-06-06T13:15:33+00:00","dateModified":"2018-06-20T13:44:30+00:00","description":"Interested to learn more about PHP? Then check out our detailed Tutorial where we explain the basic concepts used in different aspects and conditionals!","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/php-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/php\/php-tutorial-beginners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"PHP","item":"https:\/\/www.webcodegeeks.com\/category\/php\/"},{"@type":"ListItem","position":3,"name":"PHP Tutorial for Beginners &#8211; The Ultimate Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22","name":"Fabio Cimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","caption":"Fabio Cimo"},"description":"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.","sameAs":["https:\/\/www.facebook.com\/fabiocimo","https:\/\/al.linkedin.com\/in\/fabiocimo","https:\/\/x.com\/fabiocimo","https:\/\/www.youtube.com\/fabiocimo1"],"url":"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=12616"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/12616\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/930"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=12616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=12616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=12616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}