{"id":53,"date":"2026-05-20T07:11:59","date_gmt":"2026-05-20T07:11:59","guid":{"rendered":"https:\/\/gigz.pk\/php\/?post_type=lesson&#038;p=53"},"modified":"2026-05-21T14:36:58","modified_gmt":"2026-05-21T14:36:58","slug":"syntax-and-structure","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure","title":{"rendered":"Syntax and Structure"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP syntax and structure define how PHP code is written and organized so that the server can correctly understand and execute it. Learning the correct syntax is essential for building error free and efficient web applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP code is always executed on the server side and is usually embedded within HTML to create dynamic web pages.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic PHP Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A PHP script always starts with PHP opening tag and ends with closing tag.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php<br>\/\/ PHP code goes here<br>?&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Everything written inside these tags is processed by the server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Statement Rules<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each PHP statement must end with a semicolon.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Hello World\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Without a semicolon, PHP will generate an error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Tags<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP supports standard tags for writing code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Standard tag<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php<br>echo \"Welcome to PHP\";<br>?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Comments in PHP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Comments are ignored by the server and are used to explain code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Single line comment<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ This is a single line comment<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Multi line comment<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* This is a<br>multi line comment *\/<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Case Sensitivity in PHP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP is partially case sensitive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Variables are case sensitive<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$name = \"Ali\";<br>echo $Name; <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will produce an error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Keywords like echo, if, else are not case sensitive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Variables in PHP Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Variables in PHP start with a dollar sign.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$name = \"Ahmed\";<br>$age = 22;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Output Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP uses echo or print to display output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"Welcome to Website Training\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Embedding PHP in HTML<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP can be easily mixed with HTML.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;html&gt;<br>&lt;body&gt;<br><br>&lt;?php<br>echo \"Hello Students\";<br>?&gt;<br><br>&lt;\/body&gt;<br>&lt;\/html&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Code Blocks<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP code can be written in multiple blocks within the same file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php<br>echo \"First Block\";<br>?&gt;<br><br>&lt;?php<br>echo \"Second Block\";<br>?&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">PHP Data Flow Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">User Request<br>Browser sends request to server<br>Server processes PHP code<br>Server sends output to browser<br>Browser displays result<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PHP File Structure<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A typical PHP file includes<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">HTML structure<br>PHP logic<br>Database connection code if required<br>Frontend design elements<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for PHP Syntax<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Always use proper indentation<br>Always end statements with semicolons<br>Use meaningful variable names<br>Keep PHP and HTML organized<br>Write comments for better understanding<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">PHP syntax and structure are the foundation of backend development. Proper understanding helps in building clean, scalable, and error free web applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/php\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PHP Fundamentals (Beginner Level) > PHP Basics > Syntax and Structure<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1779261121886\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":6,"template":"","class_list":["post-53","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Syntax and Structure - Learn PHP with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Syntax and Structure - Learn PHP with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure\" \/>\n<meta property=\"og:site_name\" content=\"Learn PHP with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-21T14:36:58+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=syntax-and-structure\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=syntax-and-structure\",\"name\":\"Syntax and Structure - Learn PHP with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\"},\"datePublished\":\"2026-05-20T07:11:59+00:00\",\"dateModified\":\"2026-05-21T14:36:58+00:00\",\"description\":\"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=syntax-and-structure#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=syntax-and-structure\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?lesson=syntax-and-structure#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/php\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Fundamentals (Beginner Level) > PHP Basics > Syntax and Structure\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/php\\\/\",\"name\":\"Learn PHP with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Syntax and Structure - Learn PHP with GiGz.PK","description":"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.","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:\/\/gigz.pk\/php\/?lesson=syntax-and-structure","og_locale":"en_US","og_type":"article","og_title":"Syntax and Structure - Learn PHP with GiGz.PK","og_description":"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.","og_url":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure","og_site_name":"Learn PHP with GiGz.PK","article_modified_time":"2026-05-21T14:36:58+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure","url":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure","name":"Syntax and Structure - Learn PHP with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/php\/#website"},"datePublished":"2026-05-20T07:11:59+00:00","dateModified":"2026-05-21T14:36:58+00:00","description":"Learn PHP syntax and structure with simple rules, examples, and best practices for building clean and dynamic web applications.","breadcrumb":{"@id":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/php\/?lesson=syntax-and-structure#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/php"},{"@type":"ListItem","position":2,"name":"PHP Fundamentals (Beginner Level) > PHP Basics > Syntax and Structure"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/php\/#website","url":"https:\/\/gigz.pk\/php\/","name":"Learn PHP with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson\/53","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/php\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}