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;?>