Php array (3) & lt ;? Php array for loop and foreach loop $ arrarray (Xin, Hua, Sheng, state, wood, www.xinhuastm.com); for ($ i0; $ I & lt; count ($ arr ); $ I ++) {echo $ arr [$ I], & lt; br & gt ;;}optimize this question, and refine the energy efficiency into php arrays (3)
';} // Optimize this question. energy efficiency reflects a person's level ($ I = 0, $ len = count ($ arr); $ I <$ len; $ I ++) {echo $ arr [$ I],'
';}/* Result: Xinhua eco-wood www.xinhuastm.com * // this time, the for loop does not follow the rule, and the for loop does not work ..... // introduce foreach // How does foreach work? $ Arr = array ('name' => 'obo eco-time', 'URL' => 'Www .lyaibo.com ', 'writer' => 'Wang ', 'Time' => '2014-3-16 '); foreach ($ arr as $ k => $ v) {// This is to say: every cell of the loop array, assign the unit key to $ k and the value to $ v echo $ k ,'~ ', $ V ,'
';} Echo $ k ,'~ ', $ V; // when the last value is assigned/* result: name ~ IBO eco-wood url ~ Www. lyaibo. comwriter ~ John time ~ 2013-3-16time ~ * // Someone said that I don't want to print the cell value echo if I want to loop the array key'
'; Foreach ($ arr as $ v) {echo $ v ,'
';}/* Result: AIBO eco-wood www.lyaibo.com Wang 2013-3-16 * // Someone said that when I don't want to loop, I need the array value, I just want to print the array's keys cyclically foreach ($ arr as $ k) {echo $ k ,'
'; // Whether the value is printed or the $ k value is only assigned.} // someone says this/* foreach ($ arr as $ k =>) {// syntax error echo $ k ,'
';} */?>