{"id":314,"date":"2018-01-11T09:18:01","date_gmt":"2018-01-11T09:18:01","guid":{"rendered":"http:\/\/mddir.com\/how-to\/?p=314"},"modified":"2018-01-11T09:18:01","modified_gmt":"2018-01-11T09:18:01","slug":"the-php-foreach-loop","status":"publish","type":"post","link":"https:\/\/www.mddir.com\/how-to\/the-php-foreach-loop\/","title":{"rendered":"The PHP foreach Loop"},"content":{"rendered":"<p>The foreach loops work only on arrays. You can use it to loop through each key and its value pairs in an array.<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>[php]&lt;?php<br \/>\n$colors = array(&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;yellow&quot;); <\/p>\n<p>foreach ($colors as $value) {<br \/>\n  echo &quot;$value &lt;br&gt;&quot;;<br \/>\n}<br \/>\n?&gt;  [\/php]<\/p>\n<p>In the above statement, we have mentioned the variable $colors pointing to the array fields. Then we are using a foreach loop to execute the statement.<\/p>\n<p>The above will generate the following result.<\/p>\n<p><code>red<br \/>\ngreen<br \/>\nblue<br \/>\nyellow <\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The foreach loops work only on arrays. You can use it to loop through each key and its value pairs in an array. Example [php]&lt;?php<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-314","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/comments?post=314"}],"version-history":[{"count":1,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/314\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/media?parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/categories?post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/tags?post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}