{"id":59,"date":"2020-12-10T14:36:09","date_gmt":"2020-12-10T14:36:09","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/php\/?p=59"},"modified":"2026-10-29T01:28:02","modified_gmt":"2026-10-29T01:28:02","slug":"php-loops","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/php\/php-loops\/","title":{"rendered":"PHP &#8211; Loops"},"content":{"rendered":"<p>Loops in PHP are used to execute the same block of code a give number of times. We would examine the following four types of loops supported by PHP. Then we also briefly look at two important statements used with loops: break and continue.<\/p>\n<ol>\n<li><a href=\"#t1\">for Loop<\/a><\/li>\n<li><a href=\"#t2\">while Loop<\/a><\/li>\n<li><a href=\"#t3\">do&#8230;while Loop<\/a><\/li>\n<li><a href=\"#t4\">foreach Loop<\/a><\/li>\n<li><a href=\"#t5\">break and continue statements<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. for Loop<\/strong><\/h4>\n<p>The for loop is used when the number of times the loop is to be executed is known.<\/p>\n<figure id=\"attachment_60\" aria-describedby=\"caption-attachment-60\" style=\"width: 290px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-60\" src=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg\" alt=\"For Loop\" width=\"290\" height=\"278\" \/><\/a><figcaption id=\"caption-attachment-60\" class=\"wp-caption-text\">For Loop<\/figcaption><\/figure>\n<p>Syntax for the for loop is given below:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">for (initialiser; condition; increment){\r\n   code to be execute;\r\n}\r\n<\/pre>\n<p>The initialiser is used to set\u00a0 the initial value of the counter. The condition is the expression to be checked after each iteration. Increment is the expression that increments the counter. Ans example of the for loop is given below. In this example, the loop executes 10 times<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #888888;\">\/\/for loop example<\/span>\r\n    <span style=\"color: #996633;\">$x<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #996633;\">$y<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #008800; font-weight: bold;\">for<\/span>(<span style=\"color: #996633;\">$i<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>; <span style=\"color: #996633;\">$i<\/span> <span style=\"color: #333333;\">&lt;<\/span> <span style=\"color: #0000dd; font-weight: bold;\">10<\/span>; <span style=\"color: #996633;\">$i<\/span><span style=\"color: #333333;\">++<\/span>){\r\n        <span style=\"color: #996633;\">$z<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$x<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #996633;\">$y<\/span>;\r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> (<span style=\"background-color: #fff0f0;\">\"Sum of <\/span><span style=\"background-color: #eeeeee;\">$x<\/span><span style=\"background-color: #fff0f0;\"> and <\/span><span style=\"background-color: #eeeeee;\">$y<\/span><span style=\"background-color: #fff0f0;\"> is  <\/span><span style=\"background-color: #eeeeee;\">$z<\/span><span style=\"background-color: #fff0f0;\"> &lt;br&gt;\"<\/span>);\r\n        <span style=\"color: #996633;\">$x<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n        <span style=\"color: #996633;\">$y<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>;\r\n    }\r\n<span style=\"color: #557799;\">?&gt;<\/span> \r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. while Loop<\/strong><\/h4>\n<p>The while statement will execute a block of code if a test expression is true. After the code is executed, the the test expression is checked again. If it is true then repeat. This continues until the test expression is false.<\/p>\n<figure id=\"attachment_61\" aria-describedby=\"caption-attachment-61\" style=\"width: 240px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/While-loop.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-61\" src=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/While-loop.jpg\" alt=\"While loop\" width=\"240\" height=\"278\" \/><\/a><figcaption id=\"caption-attachment-61\" class=\"wp-caption-text\">While loop<\/figcaption><\/figure>\n<p>The example below is similar to that with the for loop, but this time with a while() loop.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #888888;\">\/\/for loop example<\/span>\r\n    <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #996633;\">$b<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #008800; font-weight: bold;\">while<\/span>(<span style=\"color: #996633;\">$c<\/span> <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>){\r\n        <span style=\"color: #996633;\">$c<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #996633;\">$b<\/span>; \r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> (<span style=\"background-color: #fff0f0;\">\"Sum of <\/span><span style=\"background-color: #eeeeee;\">$a<\/span><span style=\"background-color: #fff0f0;\"> and <\/span><span style=\"background-color: #eeeeee;\">$b<\/span><span style=\"background-color: #fff0f0;\"> is <\/span><span style=\"background-color: #eeeeee;\">$c<\/span><span style=\"background-color: #fff0f0;\"> &lt;br&gt;\"<\/span>); \r\n        <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>; \r\n        <span style=\"color: #996633;\">$b<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span>;\r\n    }\r\n<span style=\"color: #557799;\">?&gt;<\/span>     \r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. do&#8230;while Loop<\/strong><\/h4>\n<p>This is similar to the while loop but it would execute the block of code at least 1 time. This is because the conditional expression comes after the block of code<\/p>\n<p>The syntax is:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">do {\r\n   code to be executed;\r\n}\r\nwhile (condition);\r\n<\/pre>\n<p>The following example will increment the value of the variable at least one time.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #996633;\">$b<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>;\r\n    <span style=\"color: #008800; font-weight: bold;\">do<\/span>{\r\n        <span style=\"color: #996633;\">$c<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #996633;\">$b<\/span>; \r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> (<span style=\"background-color: #fff0f0;\">\"Sum of <\/span><span style=\"background-color: #eeeeee;\">$a<\/span><span style=\"background-color: #fff0f0;\"> and <\/span><span style=\"background-color: #eeeeee;\">$b<\/span><span style=\"background-color: #fff0f0;\"> is <\/span><span style=\"background-color: #eeeeee;\">$c<\/span><span style=\"background-color: #fff0f0;\"> &lt;br&gt;\"<\/span>); \r\n        <span style=\"color: #996633;\">$a<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>; \r\n        <span style=\"color: #996633;\">$b<\/span> <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">3<\/span>;\r\n    }\r\n    <span style=\"color: #008800; font-weight: bold;\">while<\/span>(<span style=\"color: #996633;\">$c<\/span> <span style=\"color: #333333;\">&lt;=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">20<\/span>)\r\n<span style=\"color: #557799;\">?&gt;<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. foreach Loop<\/strong><\/h4>\n<p>The foreach statement is normally used to loop through array of values. For each iteration of the loop, the array element is assigned to a variable and the pointer moves to the next element. The syntax is:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">foreach (array as value) {\r\n   code to be executed;\r\n}\r\n<\/pre>\n<p>In the example below, we use a foreach loop to output all the values of an array.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #996633;\">$names<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">array<\/span>(<span style=\"background-color: #fff0f0;\">\"Jadon\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Solace\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Adaoma\"<\/span>);\r\n    <span style=\"color: #008800; font-weight: bold;\">foreach<\/span>(<span style=\"color: #996633;\">$names<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #996633;\">$name<\/span>){\r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> <span style=\"background-color: #fff0f0;\">\"<\/span><span style=\"background-color: #eeeeee;\">$name<\/span><span style=\"background-color: #fff0f0;\"> &lt;br&gt;\"<\/span>;\r\n    }\r\n<span style=\"color: #557799;\">?&gt;<\/span>  \r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. break and continue statements<\/strong><\/h4>\n<p>The break statement is used to exit from a a loop even if the loop has not completed its execution. An example of this is with the switch statement discussed under <a href=\"https:\/\/kindsonthegenius.com\/php\/php-conditional-statement\/\" target=\"_blank\" rel=\"noopener\">Conditional Statements<\/a>.<\/p>\n<p>The continue statement is used to skip the current iteration of a loop. For example consider the code below, we use the continue statement, with a foreach loop to skip the output for a particular name.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #557799;\">&lt;?php<\/span>\r\n    <span style=\"color: #996633;\">$names<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #008800; font-weight: bold;\">array<\/span>(<span style=\"background-color: #fff0f0;\">\"Ofure\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Solace\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Esther\"<\/span>);\r\n    <span style=\"color: #008800; font-weight: bold;\">foreach<\/span>(<span style=\"color: #996633;\">$names<\/span> <span style=\"color: #008800; font-weight: bold;\">as<\/span> <span style=\"color: #996633;\">$name<\/span>){\r\n        <span style=\"color: #008800; font-weight: bold;\">if<\/span>(<span style=\"color: #996633;\">$name<\/span> <span style=\"color: #333333;\">==<\/span> <span style=\"background-color: #fff0f0;\">\"Solace\"<\/span>)\r\n            <span style=\"color: #008800; font-weight: bold;\">continue<\/span>;\r\n        <span style=\"color: #008800; font-weight: bold;\">echo<\/span> <span style=\"background-color: #fff0f0;\">\"<\/span><span style=\"background-color: #eeeeee;\">$name<\/span><span style=\"background-color: #fff0f0;\"> &lt;br&gt;\"<\/span>;\r\n    }\r\n<span style=\"color: #557799;\">?&gt;<\/span>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Loops in PHP are used to execute the same block of code a give number of times. We would examine the following four types of &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[1],"tags":[4],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-php-loops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP - Loops | Kindson The Genius<\/title>\n<meta name=\"description\" content=\"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kindsonthegenius.com\/php\/php-loops\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP - Loops | Kindson The Genius\" \/>\n<meta property=\"og:description\" content=\"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kindsonthegenius.com\/php\/php-loops\/\" \/>\n<meta property=\"og:site_name\" content=\"PHP Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-10T14:36:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-29T01:28:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"290\" \/>\n\t<meta property=\"og:image:height\" content=\"278\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\"},\"headline\":\"PHP &#8211; Loops\",\"datePublished\":\"2020-12-10T14:36:09+00:00\",\"dateModified\":\"2026-10-29T01:28:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/\"},\"wordCount\":398,\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/For-Loop.jpg\",\"keywords\":[\"PHP Loops\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/\",\"name\":\"PHP - Loops | Kindson The Genius\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/For-Loop.jpg\",\"datePublished\":\"2020-12-10T14:36:09+00:00\",\"dateModified\":\"2026-10-29T01:28:02+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\"},\"description\":\"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/For-Loop.jpg\",\"contentUrl\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/For-Loop.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/php-loops\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP &#8211; Loops\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#website\",\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/\",\"name\":\"PHP Tutorial\",\"description\":\"Beginner to Expert With Practicals\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/#\\\/schema\\\/person\\\/a2dcea4c76668e90e5842583fd5a5f60\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/kindsonthegenius.com\\\/php\\\/author\\\/kindsonthegenius-3\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP - Loops | Kindson The Genius","description":"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","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:\/\/kindsonthegenius.com\/php\/php-loops\/","og_locale":"en_US","og_type":"article","og_title":"PHP - Loops | Kindson The Genius","og_description":"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","og_url":"https:\/\/kindsonthegenius.com\/php\/php-loops\/","og_site_name":"PHP Tutorial","article_published_time":"2020-12-10T14:36:09+00:00","article_modified_time":"2026-10-29T01:28:02+00:00","og_image":[{"width":290,"height":278,"url":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#article","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60"},"headline":"PHP &#8211; Loops","datePublished":"2020-12-10T14:36:09+00:00","dateModified":"2026-10-29T01:28:02+00:00","mainEntityOfPage":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/"},"wordCount":398,"image":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg","keywords":["PHP Loops"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/","url":"https:\/\/kindsonthegenius.com\/php\/php-loops\/","name":"PHP - Loops | Kindson The Genius","isPartOf":{"@id":"https:\/\/kindsonthegenius.com\/php\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#primaryimage"},"image":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#primaryimage"},"thumbnailUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg","datePublished":"2020-12-10T14:36:09+00:00","dateModified":"2026-10-29T01:28:02+00:00","author":{"@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60"},"description":"PHP - Loops \u2014 free PHP tutorial by Kindson Munonye with clear examples. Step-by-step for beginners. Part of Kindson The Genius. Free online.","breadcrumb":{"@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kindsonthegenius.com\/php\/php-loops\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#primaryimage","url":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg","contentUrl":"https:\/\/kindsonthegenius.com\/php\/wp-content\/uploads\/2020\/12\/For-Loop.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/kindsonthegenius.com\/php\/php-loops\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/kindsonthegenius.com\/php\/"},{"@type":"ListItem","position":2,"name":"PHP &#8211; Loops"}]},{"@type":"WebSite","@id":"https:\/\/kindsonthegenius.com\/php\/#website","url":"https:\/\/kindsonthegenius.com\/php\/","name":"PHP Tutorial","description":"Beginner to Expert With Practicals","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kindsonthegenius.com\/php\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/kindsonthegenius.com\/php\/#\/schema\/person\/a2dcea4c76668e90e5842583fd5a5f60","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b9d710de456c3d85e5614c3a6992fa3d527425e2ab32b8bd5d85bfbaa235004b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/kindsonthegenius.com\/php\/author\/kindsonthegenius-3\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":1,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":62,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/posts\/59\/revisions\/62"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/php\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}