<html> <head> <title> test array </title> </head> <body> <?php //declar a array use way 1 $Person[0] = "andylin"; $Person[1] = "lihong"; $Person[2] = "congfeng"; $Creator['Light bulb'] = 'Edison'; $Creator['Rotary Engine'] = "Wankel"; $Creator['Toilet'] = "Crapper"; //declar a array use way 2 $Person2 = array("andylin02", "lihong02", "congfeng02"); $Creator2 = array("Light bulo 2" => "Edison02", "Rotary Engine02" => "Wankel", "Toilet" => "Crapper"); //print araray PrintArray($Person, $Creator); PrintArray($Person2, $Creator2); //sort array sort($Person); asort($Creator); echo "After sort...<br>/n"; PrintArray($Person, $Creator); //[] auto add index $arr[] = "1"; $arr[] = "2"; print_r($arr); ?> <?php function PrintArray($Person, $Creator) { if (!is_array($Person) || !is_array($Creator)) { echo "erro param!<br>/n"; return; } echo "------ print for array --------<br>/n"; foreach ($Person as $name) { echo "Hello, $name<br>/n"; } foreach ($Creator as $invention => $inverntor) { echo "$inverntor created the $invention<br>/n"; } echo "<br><br>/n/n"; } ?> </body> </html>