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