{"id":327,"date":"2018-01-11T10:13:12","date_gmt":"2018-01-11T10:13:12","guid":{"rendered":"http:\/\/mddir.com\/how-to\/?p=327"},"modified":"2018-01-11T10:13:12","modified_gmt":"2018-01-11T10:13:12","slug":"loop-through-an-indexed-array","status":"publish","type":"post","link":"https:\/\/www.mddir.com\/how-to\/loop-through-an-indexed-array\/","title":{"rendered":"Loop Through an Indexed Array"},"content":{"rendered":"<p>You can use for loop to get the indexed array result<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>[php]&lt;?php<br \/>\n$cars = array(&quot;Volvo&quot;, &quot;BMW&quot;, &quot;Toyota&quot;);<br \/>\n$arrlength = count($cars);<\/p>\n<p>for($x = 0; $x &lt; $arrlength; $x++) {<br \/>\n    echo $cars[$x];<br \/>\n    echo &quot;&lt;br&gt;&quot;;<br \/>\n}<br \/>\n?&gt;[\/php]<\/p>\n<p>In the above code, we are telling php script to first count the array length. We have defined the variable <code>$arrlenght<\/code> to array length. In the next statement, we are using for loop code. In that, we have disclosed the <code>$x<\/code> value to 0. The <code>$x<\/code> is stated it is lower than the <code>$arrlength<\/code> count and in the condition we are asking it increments it by one. Then we are running the echo statement to get the value.<\/p>\n<p>The above code will show the result.<\/p>\n<p><code>Volvo<br \/>\nBMW<br \/>\nToyota<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can use for loop to get the indexed array result Example [php]&lt;?php $cars = array(&quot;Volvo&quot;, &quot;BMW&quot;, &quot;Toyota&quot;); $arrlength = count($cars); for($x = 0; $x<\/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-327","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/327","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=327"}],"version-history":[{"count":1,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":328,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/posts\/327\/revisions\/328"}],"wp:attachment":[{"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mddir.com\/how-to\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}