PHp learning 2 (array exercises)

Source: Internet
Author: User
PHp's Learning Path 2 (array exercises) is about array exercises. php is different from java and c ++ in terms of weak language, php array is very powerful... it has both the features of arrays in java and the use of collections. & Nbsp; & lt ;? Php // traverse the array. Method 1: print the variable $ a = ar PHp learning path 2 (array exercise)
For array exercises, php is a weak language different from java and c ++, php array is very powerful... it has both the features of arrays in java and the use of collections.
 
 
 "; // Traverse the array. Method 2: print the 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"); // traverses the array. Method 4: print the variable list ($ key, $ value) = each ($ MyAdd); echo "value: $ value
"; // Traverse the array. Method 5: The 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 ($ array7); $ arrayValue = current ($ array7); echo $ arrayKey. ":". $ arrayValue?> Array Functions: 1. array merging
"; $ Array = $ array7 + $ _ Array; var_dump ($ array); // array operator. /** Sort by identifier (): Sort by array identifier * krsort (): Sort by array identifier in reverse order * uksort (): sort array identifiers using custom comparison functions ***/$ fruits = array ("e" => "orange", "a" => "banana ", "c" => "apple", "d" => "lemon"); krsort ($ fruits); echo"
Sorting function:
"; Foreach ($ fruits as $ key8 => $ value8) {echo" $ key8 = $ value8
";} Ksort ($ fruits); echo"
Sorting function:
"; Foreach ($ fruits as $ key8 => $ value8) {echo" $ key8 = $ value8
";}// Asort ($ fruits); // sort print_r ($ fruits); echo"
"; Rsort ($ fruits); // sort print_r ($ fruits) in ascending order;?>

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.