The Foreach function (PHP4/PHP5) foreach syntax structure provides a simple way to traverse arrays. Foreach can only be applied to arrays and objects. If you try to apply it to variables of other data types or uninitialized variables, an error message will be sent. There are two Syntax: [php] foreach (array_expression as $ value) statement foreach (array_expression as $ key => $ value) statement foreach (array_expression as $ value) statementforeach (array_expression as $ key => $ value) statement Example 1: [php] <? Php $ arr = array (1, 2, 4); foreach ($ arr as $ value) {echo $ value. "<br/>" ;}?> <? Php $ arr = array (1, 2, 4); foreach ($ arr as $ value) {echo $ value. "<br/>" ;}?> Example 2: [php] <? Php $ arr = array (1, 2, 4); foreach ($ arr as $ key => $ value) {echo $ key. "====> ". $ value. "<br/>" ;}?> <? Php $ arr = array (1, 2, 4); foreach ($ arr as $ key => $ value) {echo $ key. "====> ". $ value. "<br/>" ;}?>