Skip to main content

Posts

Showing posts with the label loop

LOOPS

for loop: for($start=0; $start < 11; $start++) { echo "for loop test";//text will be printed 11 times } while loop: while (condition) { //statement } do while loop: do statement while (condition) The difference is that your statement gets executed at least once. In a normal while loop, the condition could be met before your statement gets executed.

FOR EACH LOOP AND ASSOCIATIVE ARRAY

You can iterate over an associative array using for each loop like below $arr=array("one"=>1,"two"=>2,"three"=>3); foreach ($arr as $key => $value) { print "Key = " . $key . " Value = " . $value . " "; } you can get array keys by using $keys=array_keys($arr); now $keys contain array of keys;//array(“one”,”two”,”three”);