{"id":4061,"date":"2022-01-26T11:07:38","date_gmt":"2022-01-26T11:07:38","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=4061"},"modified":"2022-02-17T07:13:46","modified_gmt":"2022-02-17T07:13:46","slug":"html-friendly-loops","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/loops\/html-friendly-loops","title":{"rendered":"HTML friendly loops"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">for loop<\/h4>\n\n\n\n<p>Instead of brackets you can use : and endfor;, to make a loop much easier to see within HTML code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul>\r\n&lt;?php\r\nfor ($i = 0; $i &lt; 2; $i++):\r\n?>\r\n&lt;li>Item A&lt;\/li>\r\n&lt;?php\r\nendfor;\r\n?>\r\n&lt;li>Item Z&lt;\/li>\r\n&lt;\/ul>\n\n\n\/\/Or you can use like this:\n&lt;ul>\n&lt;?php for ($i = 0; $i &lt; 2; $i++): ?>\n&lt;li>Item A&lt;\/li>\n&lt;?php endfor; ?>\n&lt;li>Item Z&lt;\/li>\n&lt;\/ul><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">foreach loop<\/h4>\n\n\n\n<p>Same, but the end keyword is endforeach;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul>\r\n&lt;?php\r\n$array = &#91;0, 1];\r\nforeach ($array as $i):\r\n?>\r\n&lt;li>Item A&lt;\/li>\r\n&lt;?php\r\nendforeach;\r\n?>\r\n&lt;li>Item Z&lt;\/li>\r\n&lt;\/ul><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">while loop<\/h4>\n\n\n\n<p> Same, but the end keyword is endwhile; <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ul>\r\n&lt;?php\r\n$i = 0;\r\nwhile ($i &lt; 2):\r\n?>\r\n&lt;li>Item A&lt;\/li>\r\n&lt;?php\r\n$i++;\r\nendwhile;\r\n?>\r\n&lt;li>Item Z&lt;\/li>\r\n&lt;\/ul><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>for loop Instead of brackets you can use : and endfor;, to make a loop much easier to see within HTML code foreach loop Same, but the end keyword is endforeach; while loop Same, but the end keyword is endwhile;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[260],"tags":[],"class_list":["post-4061","post","type-post","status-publish","format-standard","hentry","category-loops"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4061","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=4061"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4061\/revisions"}],"predecessor-version":[{"id":4064,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/4061\/revisions\/4064"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=4061"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=4061"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=4061"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}