PHP Learning Path 2 (array exercises)

Source: Internet
Author: User
PHP Learning Path II (array exercises)
For an array of exercises, PHP is different from Java and C + + He is a weak type of language, and PHP arrays are very powerful. It has both the properties of the array in Java and the purpose of the collection.
 ";//Traversal array, method two: Print variable print_r ($a); echo"
";? > ' Http://www.sina.com ', ' baidu ' = ' http://www.baidu.com ', ' google ' = ' http://www.google.com '); foreach ($_array as $add = > $myarray) {echo $add. ":". $myarray. "
";}? > "Hello", 2=> "Nihao", 3=> "LLO"); Iterate through the array, method four: Print the variable list ($key, $value) =each ($MYADD); The echo value is: $value
"; Iterate through the array, method five: List print variable $addtest=each ($MYADD); Echo $addTest [key]. "
"; echo $addTest [value]."
"; $addTest =each ($MYADD); echo $addTest [0]."
"; Echo $addTest [1]."
";? > ");}? > ' Http://www.sina.com ', ' Baidu 7 ' = ' http://www.baidu.com ', ' Google 7 ' = ' http://www.google.com '); $arrayKey =key ($array 7); $arrayValue =current ($array 7); echo $arrayKey. ":". $arrayValue?> Array function Usage: 1. Array merging
"; $array = $array 7+$_array;var_dump ($array); Array operator. /* * Sort by identifier Ksort (): Sort by Array identifier * KRSORT (): Sort by array identifier in reverse order * Uksort (): Use a user-defined comparison function to sort the array identifier * * */$fruits =array ("E" =&G t; " Orange "," a "=" banana "," C "and" Apple "," D "and" Lemon "; Krsort ($fruits); echo "
Sort function:
"; foreach ($fruits as $key 8=> $value 8) {echo" $key 8= $value 8
";} Ksort ($fruits); echo "
Sort function:
"; foreach ($fruits as $key 8=> $value 8) {echo" $key 8= $value 8
";} Asort ($fruits);//From small to Large Array print_r ($fruits); echo "
"; Rsort ($fruits); From large to small sort print_r ($fruits);? >

  • 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.