Php array (3)

Source: Internet
Author: User
Php array (3) & lt ;? Php // for loop and foreach loop of arrays $ arr = array ('sin', 'hua', 'sheng', 'status', 'M ', 'www .xinhuastm.com '); for ($ I = 0; $ I & lt; count ($ arr); $ I ++) {echo $ Play php array (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 ,'
';} */?>


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.