Play the PHP Array (3)

Source: Internet
Author: User
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, '
'; } */?>


  • Related Article

    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.