{"id":692,"date":"2021-12-03T06:58:10","date_gmt":"2021-12-03T06:58:10","guid":{"rendered":"https:\/\/swatilathia.wordpress.com\/?page_id=692"},"modified":"2023-04-22T12:16:38","modified_gmt":"2023-04-22T12:16:38","slug":"php-tutorials","status":"publish","type":"page","link":"https:\/\/swatilathia.com\/?page_id=692","title":{"rendered":"PHP Tutorials"},"content":{"rendered":"<body>\n<p class=\"has-medium-font-size\">PHP is the most popular web scripting language specially to create dynamic web pages \/ websites. PHP is a server side scripting language. Initially, PHP was \u201c<strong>Personal Home Page<\/strong>\u201c, developed by <strong><em>Rasmus Lerdorf<\/em><\/strong>. Now PHP stands for \u201c<strong>Hypertext PreProcessor<\/strong>\u201c.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">PHP is very easy to use language for beginners for website development. It is a widely used &amp; open source language. PHP is popularly used to create the majority of e-commerce websites, bloggers, any many other web applications.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69dd85c5ede1a\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69dd85c5ede1a\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#PHP_File\" >PHP File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Use_of_PHP\" >Use of PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#What_do_you_need\" >What do you need?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Where_to_write_PHP_code\" >Where to write PHP code?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#PHP_Syntax\" >PHP Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Comments_in_PHP\" >Comments in PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#How_to_printoutput_in_PHP_print\" >How to print\/output in PHP (print)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#How_to_printoutput_in_PHP_echo\" >How to print\/output in PHP (echo)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#PHP_Data_Types\" >PHP Data Types<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#PHP_Variables\" >PHP Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#PHP_Operators\" >PHP Operators<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Arithmetic_Operators\" >Arithmetic Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Assignment_Operators\" >Assignment Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Comparision_Operators\" >Comparision Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#IncrementingDecrementing_Operators\" >Incrementing\/Decrementing Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Logical_Operators\" >Logical Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#String_Operators\" >String Operators<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#User_Defined_Function_UDF\" >User Defined Function (UDF)<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_UDF\" >Structure of UDF<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_1_UDF_without_arguments\" >Example 1 : UDF without arguments<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_2_UDF_with_arguments_Call_by_Value\" >Example 2 : UDF with arguments (Call by Value)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_3_Default_argument_function\" >Example 3 : Default argument function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_4_Return_function\" >Example 4 : Return function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#_Example_5_Variable_function\" >\u00a0Example 5 : Variable function<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Scope_of_a_Variable\" >Scope of a Variable<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_1_Local_Scope_and_Global_Scope\" >Example 1 : Local Scope and Global Scope<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_2_Using_global_keyword\" >Example 2 : Using global keyword<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_3_Using_GLOBALS\" >Example 3 : Using $GLOBALS<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_4_Static_Scope\" >Example 4 : Static Scope<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Conditional_Structure\" >Conditional Structure<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_If_statement\" >Structure of If statement<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_1_If_statement\" >Example 1 : If statement<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_If_%E2%80%A6_else_statement\" >Structure of If \u2026 else statement<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_2_If_%E2%80%A6_else_statement\" >Example 2 : If \u2026 else statement<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-35\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_If_%E2%80%A6_elseif_%E2%80%A6_else_statement\" >Structure of If \u2026 elseif \u2026 else statement<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-36\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_3_If_%E2%80%A6_elseif_%E2%80%A6_else_statement\" >Example 3 : If \u2026 elseif \u2026 else statement<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-37\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_Switch_case_statement\" >Structure of Switch case statement<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-38\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_4_Switch_case_statement\" >Example 4 : Switch case statement<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-39\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Looping_Structure\" >Looping Structure<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-40\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_While_loop\" >Structure of While loop<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-41\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_1_While_loop\" >Example 1 : While loop<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-42\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_Do_%E2%80%A6_while_loop\" >Structure of Do \u2026 while loop<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-43\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Example_2_Do_%E2%80%A6_while_loop\" >Example 2 : Do \u2026 while loop<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-44\" href=\"https:\/\/swatilathia.com\/?page_id=692\/#Structure_of_for_loop\" >Structure of for loop<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_File\"><\/span>PHP File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">PHP files may contain simple text, HTML, CSS, JavaScript &amp; PHP code itself.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">On the server, PHP code is performed, and the result is sent to the browser as plain HTML.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">This file is saved as .php extension in your web directory (For wamp server, <strong>C:\/wamp\/www<\/strong> is a default web directory)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Use_of_PHP\"><\/span>Use of PHP<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>PHP is used to collect the data from HTML form. <\/li>\n\n\n\n<li>PHP is used to insert, update &amp; delete the data in database. <\/li>\n\n\n\n<li>PHP is used to create a session on server side to identify the user. <\/li>\n\n\n\n<li>PHP is used to send &amp; receive the cookies on client\u2019s computer. <\/li>\n\n\n\n<li>PHP also works with AJAX to reduce loading time of whole page.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_do_you_need\"><\/span>What do you need?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Find for a web host that supports PHP and MySQL. <\/li>\n\n\n\n<li>Install a web server on your own PC, and then install PHP and MySQL.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\">You can also use WAMP which consists of Apache web server, MySQL database and PHP programming language. WAMP is used to host PHP pages. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_to_write_PHP_code\"><\/span>Where to write PHP code?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">PHP code can be written in notepad, notepad++, Dreamweaver or any other PHP designer editor. This file with PHP code has .php extension.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_Syntax\"><\/span>PHP Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>You can write PHP script\/code anywhere in web page. <\/li>\n\n\n\n<li>It start with <strong><em>&lt;?php<\/em><\/strong> and ends with <strong><em>?&gt;<\/em><\/strong><\/li>\n\n\n\n<li>Apart from PHP code, file may contain HTML tags, JavaScript &amp; CSS.<\/li>\n\n\n\n<li>PHP statement must end with<strong><em> ; (semicolon)<\/em><\/strong>.<\/li>\n\n\n\n<li>In PHP, variable names are case-sensitive. Though, all user defined function name, classes, built in functions, keywords are not case sensitive.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\">For more practical information, See <a href=\"https:\/\/swatilathia.com\/php-video-tutorial\/#Introduction_to_PHP_How_to_save_PHP_file_How_to_write_PHP_code\">https:\/\/swatilathia.com\/php-video-tutorial\/#Introduction_to_PHP_How_to_save_PHP_file_How_to_write_PHP_code<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n       \/\/Code here\n?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Comments_in_PHP\"><\/span>Comments in PHP<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Comments are not a part of the program to be executed. <\/li>\n\n\n\n<li>It is just to inform the user what the program is all about. <\/li>\n\n\n\n<li>It allows people to comprehend your code. <\/li>\n\n\n\n<li>It reminds you what you performed in the program so that when you check it, you easily understand what the program is about.<\/li>\n\n\n\n<li>There are mainly 3 types of comments in PHP. Look at the following script:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;html&gt;\n&lt;body&gt;\n&lt;?php\n      \/\/This is Single line Comment\n      # This is Unix Shell style single line comment\n      \/* Hello Students\n         This is Swati Lathia\n         &amp; Here i am using Multiline comment\n       *\/\n?&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_printoutput_in_PHP_print\"><\/span>How to print\/output in PHP (print)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">In PHP, <strong>print<\/strong>\u00a0is used to output a string. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>print<\/strong> is not a function but a language construct. Its argument is the expression following the <strong>print<\/strong> keyword. <strong>print<\/strong> always returns 1.<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tprint \"Hello World\";\n\t\n        \/\/to new line use &lt;br&gt; in \"\"\/''(double\/single quotes)\n\tprint \"&lt;br&gt;\";\n\t\n        \/\/to print the result of expression\n\tprint (10+20)*30;\n\t\/*Output of above statement is 900\n\tthe parentheses cause 10+20 to be evaluated first\n\tthen 30*30 and the print statement sees the whole      \n\texpression as one argument *\/\n\t\n\t\/\/Every HTML tag can be used by \"\"\/'' with print\n\tprint \"&lt;br&gt;&lt;font size=6 color=red&gt;Hi Swati&lt;\/font&gt;\";\n?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_printoutput_in_PHP_echo\"><\/span>How to print\/output in PHP (echo)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">In PHP, to output one or more strings we can also use <strong>echo<\/strong>. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>echo<\/strong> is not a function but a language construct. Its arguments are a list of expressions following the <strong>echo<\/strong> keyword, separated by commas. echo does not return any value.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">The main differences between <strong>print<\/strong>\u00a0and <strong>echo<\/strong> are that echo accepts multiple arguments and doesn\u2019t have a return value.<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\necho \"This does not require parentheses.\";\n\n\/\/to print multiple arguments\necho '&lt;br&gt;This ', 'is ', 'Swati ', 'Lathia ', 'from HJD.';\n\t\n\/*concatenated together and passed as a single argument*\/\necho '&lt;br&gt;This '. 'is '. 'Swati '. 'Lathia '. 'from HJD.';\n\n\/\/to new line use &lt;br&gt; in \"\"\/''(double\/single quotes)\necho \"&lt;br&gt;\";\n\t\n\/\/to output the result of expression\necho (10+20)*30;\n\/* Output of above statement is 900\nthe parentheses cause 10+20 to be evaluated first\nthen 30*30 and the echo statement sees the whole      \nexpression as one argument *\/\n\t\n\/\/Every HTML tag can be used by \"\"\/'' with echo\necho \"&lt;br&gt;&lt;font size=6 color=red&gt;Hi Swati&lt;\/font&gt;\";\n?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_Data_Types\"><\/span>PHP Data Types<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">Since PHP is a dynamically typed language, there is no need to specify the type of a variable by default as it will be determined at runtime.<\/p>\n\n\n\n<p class=\"has-medium-font-size\">Depending on its value, PHP has one of the following built-in kinds:<\/p>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>null<\/li>\n\n\n\n<li>bool<\/li>\n\n\n\n<li>int<\/li>\n\n\n\n<li>float\u00a0(also called Double)<\/li>\n\n\n\n<li>string<\/li>\n\n\n\n<li>array<\/li>\n\n\n\n<li>object<\/li>\n\n\n\n<li>resource<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_Variables\"><\/span>PHP Variables<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"has-medium-font-size\">A PHP programme uses variables to store values or data that can be used at a later time. The variables are also containers that hold strings, memory addresses, character values, and numeric values. In PHP, to declare and store variables follow these rules:<\/p>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li class=\"has-medium-font-size\">Each variable declaration starts with a dollar sign ($), then the variable name.<\/li>\n\n\n\n<li>PHP variable name must start with either alphanumeric characters or underscores (for example, \u2018a-z\u2019, \u2018A-Z\u2019, \u20180-9, and \u2018_\u2019) in their name. <\/li>\n\n\n\n<li>PHP variable cannot start with a number.<\/li>\n\n\n\n<li>PHP variable is case-sensitive. For example, $var and $VAR both are different.<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\">For more practical information <a href=\"https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Variable_Data_Types\">https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Variable_Data_Types<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size\">Let us take an example of variables and their different data type<\/p>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n        \/\/initializing integer type of variable\n\t$total=80;\n\techo \"Total marks = \".$total.\"&lt;br&gt;\";\n\t\n\t\/\/initializing float\/double variable\n\t$percent=70.67;\n\techo \"Percentage = \".$percent.\"&lt;br&gt;\";\n\t\n\t\/\/initializing string\/charcater variable\n\t$name=\"Swati Lathia\";\n\techo \"Hi this is \".$name.\"&lt;br&gt;\";\n\t\n\t\/\/initializing boolean variable\n\t\/\/true is 1 and false is 0\n\t$flag=true;\n\techo \"The value of flag is = \".$flag;\n?&gt;\nOutput\nTotal marks = 80\nPercentage = 70.67\nHi this is Swati Lathia\nThe value of flag is = 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"PHP_Operators\"><\/span>PHP Operators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Here, we are discussing mainly six types of operators of PHP : Arithmetic, Assignment, Comparision, Incrementing\/Decrementing, Logical and String\u00a0operators: <\/li>\n\n\n\n<li>Let us start every operator with example of each one.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Arithmetic_Operators\"><\/span>Arithmetic Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table class=\"has-white-background-color has-background\" style=\"border-width:3px\"><thead><tr><th>Operation<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Identity<\/td><td>+$no1<\/td><td>$no1 is converted to int or float as needed.<\/td><\/tr><tr><td>Negation<\/td><td>-$no1<\/td><td>Opposite of $no1<\/td><\/tr><tr><td>Addition<\/td><td>$no1+$no2<\/td><td>Sum of $no1 and $no2<\/td><\/tr><tr><td>Subtraction<\/td><td>$no1-$no2<\/td><td>Difference of $no1 and $no2<\/td><\/tr><tr><td>Multiplication<\/td><td>$no1*$no2<\/td><td>Multiply $no1 and $no2<\/td><\/tr><tr><td>Division<\/td><td>$no1\/$no2<\/td><td>Quotient of $no1 and $no2<\/td><\/tr><tr><td>Modulo<\/td><td>$no1%$no2<\/td><td>Remainder of $no1 divided by $no2<\/td><\/tr><tr><td>Exponentiation<\/td><td>$no1**$no2<\/td><td>Result of raising $no1 to the\u00a0power $no2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Assignment_Operators\"><\/span>Assignment Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>The basic assignment operator is \u201c=\u201d.\u00a0<\/li>\n\n\n\n<li class=\"has-medium-font-size\">Here we are discussing Arithmetic assignment operators with examples.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table style=\"border-width:3px\"><thead><tr><th>Operation<\/th><th>Example<\/th><th>Equivalent to<\/th><\/tr><\/thead><tbody><tr><td>Addition<\/td><td>$n1+=$n2<\/td><td>$n1=$n1+$n2<\/td><\/tr><tr><td>Subtraction<\/td><td>$n1-=$n2<\/td><td>$n1=$n1-$n2<\/td><\/tr><tr><td>Multiplication<\/td><td>$n1*=$n2<\/td><td>$n1=$n1*$n2<\/td><\/tr><tr><td>Division<\/td><td>$n1\/=$n2<\/td><td>$n1=$n1\/$n2<\/td><\/tr><tr><td>Modulus<\/td><td>$n1%=$n2<\/td><td>$n1=$n1%$n2<\/td><\/tr><tr><td>Exponentiation<\/td><td>$n1**=$n2<\/td><td>$n1=$n1**$n2<\/td><\/tr><tr><td>String Concatenation<br>(Joins two or more strings)<\/td><td>$n1.=$n2<\/td><td>$n1=$n1.$n2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Comparision_Operators\"><\/span>Comparision Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>As the name implies, comparison operators allow you to compare two values.<\/li>\n\n\n\n<li>Let us check every operator with example.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table style=\"border-width:3px\"><thead><tr><th>Operation<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Equal<\/td><td>$no1==$no2<\/td><td>True, if $no1 and $no2 have same value<\/td><\/tr><tr><td>Identical<\/td><td>$no1===$no2<\/td><td>True, if and only if $no1 and $no2 have same value and data type as well<\/td><\/tr><tr><td>Not Equal<\/td><td>$no1!=$no2<\/td><td>True, if $no1 and $no2 have not same value<\/td><\/tr><tr><td>Not Equal<\/td><td>$no1&lt;&gt;$no2<\/td><td>True, if $no1 and $no2 have not same value<\/td><\/tr><tr><td>Not Identical<\/td><td>$no1!==$no2<\/td><td>True, if $no1 and $no2 have not same value or they don\u2019t have same data type<\/td><\/tr><tr><td>Less than<\/td><td>$no1&lt;$no2<\/td><td>True, if $no1 is less than $no2<\/td><\/tr><tr><td>Greater than<\/td><td>$no1&gt;$no2<\/td><td>True, if $no1 is greater than $no2<\/td><\/tr><tr><td>Less than or equal to<\/td><td>$no1&lt;=$no2<\/td><td>True, if $no1 is less than or equal to $no2<\/td><\/tr><tr><td>Greater than or equal to<\/td><td>$no1&gt;=$no2<\/td><td>True, if $no1 is greater than or equal to $no2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"IncrementingDecrementing_Operators\"><\/span>Incrementing\/Decrementing Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li class=\"has-medium-font-size\">PHP supports C style post increment\/decrement and pre increment\/decrement operators.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table style=\"border-width:3px\"><thead><tr><th>Operation<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>Pre Increment<\/td><td>++$no1<\/td><td>Increments $no1 by one, then returns $no1<\/td><\/tr><tr><td>Post Increment<\/td><td>$no1++<\/td><td>Returns $no1, then increments $no1 by one<\/td><\/tr><tr><td>Pre Decrement<\/td><td>\u2013$no1<\/td><td>Decrements $no1 by one, then returns $no1<\/td><\/tr><tr><td>Post Decrement<\/td><td>$no1\u2013<\/td><td>Returns $no1, then decrements $no1 by one<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Now let us check out every operator with example below<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a = 10;\n\techo \"Post incrementing(10) = \".$a++.\"&lt;br&gt;\";\n\techo \"Now the value is = \".$a.\"&lt;hr&gt;\";\n\n\t$b = 10;\n\techo \"Pre incrementing(10) = \".++$b.\"&lt;br&gt;\";\n\techo \"Now the value is = \".$b.\"&lt;hr&gt;\";\n\t\t\n\t$c = 10;\n\techo \"Post decrementing(10): \".$c--.\"&lt;br&gt;\";\n\techo \"Now the value is = \".$c.\"&lt;hr&gt;\";\n\n\t$d = 10;\n\techo \"Pre decrementing(10) \".--$d.\"&lt;br&gt;\";\n\techo \"Now the value is = \".$d;\n?&gt;\nOutput\nPost incrementing(10) = 10\nNow the value is = 11\n\n----------------------------------\nPreincrementing(10) = 11\nNow the value is = 11\n----------------------------------\nPost decrementing(10): 10\nNow the value is = 9\n----------------------------------\nPre decrementing(10) 9\nNow the value is = 9<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Logical_Operators\"><\/span>Logical Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<figure class=\"wp-block-table has-medium-font-size\"><table style=\"border-width:3px\"><thead><tr><th>Operation<\/th><th>Example<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td>And<\/td><td>$a and $b<\/td><td>True, if both $a &amp; $b are true<\/td><\/tr><tr><td>And<\/td><td>$a &amp;&amp; $b<\/td><td>True, if both $a &amp; $b are true<\/td><\/tr><tr><td>Or<\/td><td>$a or $b<\/td><td>True, if either $a or $b is true<\/td><\/tr><tr><td>Or<\/td><td>$a || $b<\/td><td>True, if either $a or $b is true<\/td><\/tr><tr><td>Not<\/td><td>! $a <\/td><td>True, if $a is not true<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"String_Operators\"><\/span>String Operators<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In PHP, there are two string operators \u2013 (.) that returns the concatenation of its right and left arguments and (.=) that appends the argument on the right side to the argument on the left side.<\/li>\n\n\n\n<li>Example<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n        $v1 = \"Good \";\n\t$v2 = $v1 . \"Morning!\"; \n        \/\/ now $v2 contains \"Good Morning!\"\n\techo $v2.\"&lt;hr&gt;\";\n\t\n\t$v3 = \"Hey! \";\n\t$v3 .= \"How's the day!\";     \n       \/\/ now $v3 contains \"Hey! Hows the day!\"\n\techo $v3.\"&lt;hr&gt;\";\n?&gt;\nOutput\nGood Morning!\n------------------------------------------\nHey How's the day!<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">For more practical information, See <a href=\"https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Operators_Arithmetic_Operators\">https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Operators_Arithmetic_Operators<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"User_Defined_Function_UDF\"><\/span>User Defined Function (UDF)<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>UDF is a function that is defined by the user to execute his\/her own code of programme or according to his\/her requirement. <\/li>\n\n\n\n<li>UDF is useful when we need one block of code to execute more than once in one page at a different place.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">Once you create a UDF error free, you can use it as many times as you want without writing it again. <\/li>\n\n\n\n<li class=\"has-medium-font-size\">Simple, you just need to call it with its name.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">UDF is a block of code written by the user in following format:<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_UDF\"><\/span>Structure of UDF<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n      function func_name(arg1, arg2,..)\n      {\n          body of the function\n      }\n      \/\/to call the UDF, use name of the function with parentheses\n      func_name();\n?&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">Name of the function starts with a letter or underscore, followed by any number of letters, numbers, or underscores.\u00a0<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_UDF_without_arguments\"><\/span><strong>Example 1<\/strong> : <strong>UDF without arguments<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"has-medium-font-size\">In this example, we are using variables ($a and $b) inside the function which gives the total of the two.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">These variables are known as <strong><em>local variables<\/em><\/strong>, which we will discuss later on.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>\/\/UDF without arguments\nfunction add()\n{\n\t$a=10;\n\t$b=30;\n\techo \"Total of a &amp; b = \".($a+$b);\n}\n\/\/call UDF\nadd();\n\nOutput\nTotal of a &amp; b = 40<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_UDF_with_arguments_Call_by_Value\"><\/span><strong>Example 2<\/strong> : <strong>UDF with arguments<\/strong> (Call by Value)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In this example, we are using two parameters\/ arguments inside the parentheses $a and $b. When we call the function, we must pass the values for these two variables respectively.<\/li>\n\n\n\n<li>So, when we pass 30 and 50, 30 will be assigned to $a and 50 will be assigned to $b and then we get the total of the two.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t\/\/UDF with arguments or call by values\n\tfunction add($a,$b)\n\t{\n\t\techo \"Total of a &amp; b = \".($a+$b);\n\t}\n\t\/\/call UDF with passing values\n\tadd(30,50);\n?&gt;\n\nOutput\nTotal of a &amp; b = 80<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3_Default_argument_function\"><\/span>Example 3 : Default argument function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In this type of function, we can provide value with argument to make it default.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t\/\/Default argument function\n\t\/\/Always write non-default argument at the beginning \n\tfunction add($s1,$s2=\"World\")\n\t{\n\t\techo $s1.\" \".$s2;\n\t}\n\t\/* We only pass the value for argument $s1,\n\tas $s2 is default argument*\/\n\tadd(\"Hello\");\n?&gt;\n\nOutput\nHello World<\/code><\/pre>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>If we pass the value for $s2 (default argument), that new value will override the default value. Look at the example below:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t\/\/Default argument function\n\t\/\/Always write non-default argument at the beginning \n\tfunction add($s1,$s2=\"World\")\n\t{\n\t\techo $s1.\" \".$s2;\n\t}\n\t\/\/We pass the value for argument $s1,$s2 both\n\tadd(\"Hello\",\"Swati\");\n?&gt;\nOutput \nHello Swati<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4_Return_function\"><\/span>Example 4 : Return function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>A UDF can return a value of any data type just using <strong><em>return<\/em><\/strong> statement inside the body of the function. <\/li>\n\n\n\n<li>A return statement\u00a0ends the execution of a function, and returns control to the calling function.<\/li>\n\n\n\n<li>A return is used to send a value back to where\u2019s it\u2019s called from.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t\/\/return function\n\tfunction cube($a)\n\t{\n\t\treturn ($a*$a*$a);\n\t}\n\t\/\/to print the value which return, use echo\n\techo \"The Cube of 9 = \".cube(9);\n?&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_Example_5_Variable_function\"><\/span>\u00a0Example 5 : Variable function<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>If a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it.\u00a0<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t\/\/variable function\n\tfunction demo()\n\t{\n\t\techo \"Hi i am a variable function\";\n\t}\n\t\/* variable $var has a value 'demo' \n\twhich is same as function name\n\tdeclared earlier *\/\n\t$var='demo';\n\t$var();\n?&gt;\n\nOutput\nHi i am a variable function<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">For more practical information, see <a href=\"https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_UDF_%E2%80%93_Argument_Function_and_Default_argument_function\">https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_UDF_%E2%80%93_Argument_Function_and_Default_argument_function<\/a><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><a href=\"https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Variable_as_function_Return_function_Variable_Length_Argument_Functions\">https:\/\/swatilathia.com\/php-video-tutorial\/#PHP_Variable_as_function_Return_function_Variable_Length_Argument_Functions<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Scope_of_a_Variable\"><\/span>Scope of a Variable<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>A variable\u2019s scope is the context where it has been defined.<\/li>\n\n\n\n<li>It is known as the lifetime of a variable or portion of the program within which it can be accessed.<\/li>\n\n\n\n<li>In PHP, there is three different variable scopes: local, global and static<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_Local_Scope_and_Global_Scope\"><\/span>Example 1 : Local Scope and Global Scope<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a=100;\/\/global scope\n\tfunction demo()\n\t{\n\t\t$a=10;\/\/local scope\n\t\techo \"The value of a inside UDF = \".$a.\"&lt;br&gt;\";\n\t}\n\tdemo();\n\techo \"The value of a outside UDF = \".$a.\"&lt;br&gt;\";\n?&gt;\nOutput\nThe value of a inside UDF = 10\nThe value of a outside UDF = 100<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">Any variable used inside UDF is by default local to that function. <\/li>\n\n\n\n<li class=\"has-medium-font-size\">Outside UDF variable \u2018a\u2019 does not access as 10 because it loses its value.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">But we have already declared a = 100 outside UDF, which can access outside the UDF.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">So in the above example, when we call UDF, it prints the value of a = 10 as local scope<\/li>\n\n\n\n<li class=\"has-medium-font-size\">Now when we print the value of \u2018a\u2019 outside the UDF, it prints a = 100 as we declare variable a  = 100 which represents global scope.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_Using_global_keyword\"><\/span>Example 2 : Using global keyword<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a=100;\/\/global scope\n        $b=200;\/\/global scope\n\tfunction demo()\n\t{\n\t\t\/\/global scope\n\t\tglobal $a, $b;\n\t\techo \"The value of a inside UDF = \".$a.\"&lt;br&gt;\";\n\t\techo \"The value of b inside UDF = \".$b.\"&lt;br&gt;\";\n\t}\n\tdemo();\n?&gt;\n\nOutput\nThe value of a inside UDF = 100\nThe value of b outside UDF = 200<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">If you want to use the value of global variables inside UDF, you just need to write global keyword before declaring same variable name inside UDF.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">In above example, we declare two variables : a &amp; b outside the UDF and can access inside UDF using \u201cglobal\u201d keyword.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">If you change anything in global variable inside UDF, that change reflects throughout the script.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a=100;\/\/global scope\n\t$b=200;\/\/global scope\n\tfunction demo()\n\t{\n\t\t\/\/global scope\n\t\tglobal $a, $b;\n\t\techo \"The value of a inside UDF = \".$a.\"&lt;br&gt;\";\n\t\techo \"The value of b inside UDF = \".$b.\"&lt;br&gt;\";\n\t\t$a=$a+$b;\n\t}\n\tdemo();\n\techo \"Now the value of a = \".$a.\"&lt;br&gt;\";\n?&gt;\n\nOutput\nThe value of a inside UDF = 100\nThe value of b inside UDF = 200\nNow the value of a = 300<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3_Using_GLOBALS\"><\/span>Example 3 : Using $GLOBALS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>We can use $GLOBALS to access value of global variable inside UDF.<\/li>\n\n\n\n<li>$GLOBALS is an associative array with the name of variable, which is global or super global variable.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n$a=100;\/\/global scope\n$b=200;\/\/global scope\nfunction demo()\n{\necho \"The value of a inside UDF = \".$GLOBALS['a'].\"&lt;br&gt;\";\necho \"The value of b inside UDF = \".$GLOBALS['b'].\"&lt;br&gt;\";\n}\ndemo();\n?&gt;\n\nOutput\nThe value of a inside UDF = 100\nThe value of b inside UDF = 200<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4_Static_Scope\"><\/span>Example 4 : Static Scope<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Let us look at the example below<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tfunction demo()\n\t{\n\t\t$a=10;\/\/local scope\n\t\techo $a.\"&lt;br&gt;\";\n\t\t$a++;\n\t}\n\tdemo();\n\tdemo();\n\tdemo();\n?&gt;\n\nOutput\n10\n10\n10<\/code><\/pre>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>We actually wanted to get 1, 2, 3 as we have called demo() three times. But according to local scope of a variable, when the variable leaves the UDF, it loses its value which is being incremented from 1 to 2. <\/li>\n\n\n\n<li>When we call demo() again, it prints 1 again and not 2. Likewise, third time when we call demo(), it prints 1 again and not 3.<\/li>\n\n\n\n<li>The solution of this type of problem is Static variable.<\/li>\n\n\n\n<li>To make the variable static, just write \u2018static\u2019 keyword before using variable name.<\/li>\n\n\n\n<li>Static variable does not lose its value when it leaves the UDF and it preserves what it has.<\/li>\n\n\n\n<li>Look at the example below.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tfunction demo()\n\t{\n\t\tStatic $a = 10;\/\/static scope\n\t\techo $a.\"&lt;br&gt;\";\n\t\t$a++;\n\t}\n\tdemo();\n\tdemo();\n\tdemo();\n?&gt;\n\nOutput\n10\n11\n12<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conditional_Structure\"><\/span>Conditional Structure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">Simple If, If\u2026else, If\u2026elseif\u2026else and switch case are all included in Conditional structure of PHP.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_If_statement\"><\/span>Structure of If statement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>The statement between curly braces executed if the condition is true.<\/li>\n\n\n\n<li>If the condition will be false, it will be ignored.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tif(condition)\n\t{\n\t\tstatement to be executed\n\t}\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_If_statement\"><\/span>Example 1 : If statement<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In this example, we have taken the value of a = 5 which less than 10 according to the given condition. So the given condition is being true and the statement between the curly brackets will be executed.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a = 5;\n\tif($a &lt; 10)\n\t{\n\t\techo \"a is less than 10\";\n\t}\n?&gt;\n\nOutput\na is less than 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_If_%E2%80%A6_else_statement\"><\/span>Structure of If \u2026 else statement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>The statement between curly braces executed if the condition is true.<\/li>\n\n\n\n<li>If the condition is false, the statement inside else part will be executed.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tif(condition)\n\t{\n\t\tstatement to be executed\n\t}\n\telse\n\t{\n\t\tother statement to be executed\n\t}\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_If_%E2%80%A6_else_statement\"><\/span>Example 2 : If \u2026 else statement<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>Here we have two variables a=5 and b=10. According to the condition, a is less than b, so the statement inside If will be displayed. Hence, the given If condition is true.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a = 5;\n\t$b = 10;\n\tif ($a &lt; $b)\n\t{\n\t\techo \"a is less than b\";\n\t}\n\telse\n\t{\n\t\techo \"a is not less than b\";\n\t}\n?&gt;\n\nOutput\na is less than b<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_If_%E2%80%A6_elseif_%E2%80%A6_else_statement\"><\/span>Structure of If \u2026 elseif \u2026 else statement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>If there are more than one conditions to be checked, you can use if \u2026 elseif \u2026 else statements.<\/li>\n\n\n\n<li>In this statement, if condition is not true, PHP will check for next the condition inside elseif.<\/li>\n\n\n\n<li>If elseif condition is not true, PHP will go for the else part and execute the statement inside else.<\/li>\n\n\n\n<li>You can put as many elseif as you want.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\tif (condition)\n\t{\n\t\tstatement to be executed\n\t}\n\telseif (condition)\n\t{\n\t\tstatement to be executed\n\t}\n\telseif (condition)\n\t{\n\t\tstatement to be executed\n\t}\n\telse\n\t{\n\t\tstatement to be executed\n\t}\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3_If_%E2%80%A6_elseif_%E2%80%A6_else_statement\"><\/span>Example 3 : If \u2026 elseif \u2026 else statement<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a = 10;\n\t$b = 10;\n\tif ($a &lt; $b)\n\t{\n\t\techo \"a is less than b\";\n\t}\n\telseif ($a &gt; $b)\n\t{\n\t\techo \"a is greater than b\";\n\t}\n\telse\n\t{\n\t\techo \"a and b are equal\";\n\t}\n?&gt;\n\nOutput\na and b are equal<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_Switch_case_statement\"><\/span>Structure of Switch case statement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>The Switch statement is similar to a collection of If statements on the same expression.<\/li>\n\n\n\n<li>In some cases, you may want to compare the same variable (or expression) with many different values and execute a different piece of code depending on which value it equals to.<\/li>\n\n\n\n<li>This is what Switch statement does.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\nswitch(variable\/expression) \n{\n    case 1:\n\t\tstatement to be executed\n\t\tbreak;\n    case 2:\n\t\tstatement to be executed\n\t\tbreak;\n    case 3:\n\t\tstatement to be executed\n\t\tbreak;\n    default:\n\t\tstatement to be executed\n}\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4_Switch_case_statement\"><\/span>Example 4 : Switch case statement<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>In this example, the value of $day will be compared with every case. If any case matches with the value of $day, the statement of the corresponding case will be executed.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n    $day=\"Thursday\";\n    switch($day) \n    {\n    case \"Monday\":\n\t\t\techo \"It's Monday\";\n\t\t\tbreak;\n    case \"Tuesday\":\n\t\t\techo \"It's Tuesday\";\n\t\t\tbreak;\n    case \"Wednesday\":\n\t\t\techo \"It's Wednesday\";\n\t\t\tbreak;\n    case \"Thursday\":\n\t\t\techo \"It's Thursday\";\n\t\t\tbreak;\n    case \"Friday\":\n\t\t\techo \"It's Friday\";\n\t\t\tbreak;\n    case \"Saturday\":\n\t\t\techo \"It's Saturday\";\n\t\t\tbreak;\n    default:\n\t\t\techo \"Hey It's Sunday\";\n}\n?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Looping_Structure\"><\/span>Looping Structure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>PHP has mainly four types of looping structure : While, Do \u2026 while, for and foreach.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_While_loop\"><\/span>Structure of While loop<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li>PHP executes the statement(s) repeatedly, as long as the while expression evaluates to true. <\/li>\n\n\n\n<li>The value of the expression is checked every time at the beginning of the loop, so even if this value changes during the execution of the statement(s), execution will not stop until the end of the loop. <\/li>\n\n\n\n<li>If the while expression evaluates to false from the beginning, the statement(s) will not even be executed once.<\/li>\n\n\n\n<li class=\"has-medium-font-size\">While loop is also known as entry control loop as it checks every value\/ expression before entering into the while loop.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>While(expression)\n{\n      Statement(s) to be executed\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1_While_loop\"><\/span>Example 1 : While loop<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php \n$a=1; \nwhile($a&lt;=5) \n{ \n       echo \"The value of a = \".$a.\"&lt;br&gt;\"; \n       $a++; \n} \n?&gt;\n\nOutput\nThe value of a = 1\nThe value of a = 2\nThe value of a = 3\nThe value of a = 4\nThe value of a = 5<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_Do_%E2%80%A6_while_loop\"><\/span>Structure of Do \u2026 while loop<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"has-medium-font-size wp-block-list\">\n<li class=\"has-medium-font-size\">Do.. while loop does the same job as while excepts it doesn\u2019t check the expression at the beginning of the loop. When first iteration completes, it checks for the expression at the end of the loop.<\/li>\n\n\n\n<li>That means by default do\u2026 while loop iterates one time and executes whatever inside the loop at least once.<\/li>\n\n\n\n<li>If the expression evaluates wrong, it will not iterate further.<\/li>\n\n\n\n<li>Do\u2026while loop is also known as exit control loop.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n      do{\n\t        statement(s) to be executed\n\t}while(expression);\n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2_Do_%E2%80%A6_while_loop\"><\/span>Example 2 : Do \u2026 while loop<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a=1;\n\tdo{\n\t\techo \"The value of a = \".$a.\"&lt;br&gt;\";\n\t\t$a++;\n\t}while($a&lt;=5);\n?&gt;\n\nOutput\nThe value of a = 1\nThe value of a = 2\nThe value of a = 3\nThe value of a = 4\nThe value of a = 5<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li class=\"has-medium-font-size\">In below example, the expression is not satisfied according to the value of $a, still it prints the value of a=10. Then it will stop iterating as it will check the expression at the end of the loop.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-medium-font-size\"><code>&lt;?php\n\t$a=10;\n\tdo{\n\t\techo \"The value of a = \".$a.\"&lt;br&gt;\";\n\t\t$a++;\n\t}while($a&lt;=5);\n?&gt;\n\nOutput\nThe value of a = 10<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Structure_of_for_loop\"><\/span>Structure of for loop<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<\/body>","protected":false},"excerpt":{"rendered":"<p>PHP is the most popular web scripting language specially to create dynamic web pages \/ websites. PHP is a server side scripting language. Initially, PHP was \u201cPersonal Home Page\u201c, developed by Rasmus Lerdorf. Now PHP stands for \u201cHypertext PreProcessor\u201c. PHP is very easy to use language for beginners for website development. It is a widely [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"om_disable_all_campaigns":false,"footnotes":""},"class_list":["post-692","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=692"}],"version-history":[{"count":70,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/692\/revisions"}],"predecessor-version":[{"id":2877,"href":"https:\/\/swatilathia.com\/index.php?rest_route=\/wp\/v2\/pages\/692\/revisions\/2877"}],"wp:attachment":[{"href":"https:\/\/swatilathia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}