Play PHP Array (iii)
'; } To optimize the problem, details can reflect a person's level for ($i =0, $len =count ($arr); $i < $len; $i + +) { echo $arr [$i], '
';} /* Results: Xin Hua eco-Wood www.xinhuastm.com*///This time, the for loop has no regularity to follow, then the For loop does not work ...//How does the introduction of the foreach//foreach works? $arr =array (' name ' = ' Love bo Eco-wood ', ' url ' = ' www.lyaibo.com ', ' writer ' = ' Xiao Wang ', ' time ' = ' 2013-3-16 '); foreach ($ Arr as $k + $v) {//This is to say: each cell of the loop array, assigns the key of the element to the $K, assigns the value to the $v echo $k, ' ~ ', $v, '
';} echo $k, ' ~ ', $v; Stay in the case of the last assignment/* results: name~ Eco Wood url~www.lyaibo.comwriter~ Xiao Wang time~2013-3-16time~2013-3-16*///someone said, I do not want to loop when the key to the array, I just want to cycle through each cell value echo '
'; foreach ($arr as $v) { echo $v, '
';} /* Results love Bo Eco Wood www.lyaibo.com Xiao Wang 2013-3-16*///Some people say that I do not want to loop when the value of the array, I just want to loop the print set of the key foreach ($arr as $k) { echo $k, '
'; Print or value, $k just be assigned to it}//Some people say so/* foreach ($arr as $k =) {//Syntax error echo $k, '
'; } */?>