sort function sorts array
'); sort($names); $asize=sizeof($names); for($i=0; $i<$asize; $i++) { if(($names[$i]=="Anna")||($names[$i]=="Maria")) { print($message.$prefix2.$names[$i]."
"); } else { print($message.$prefix1.$names[$i]."
"); } } print('
'); echo "function array_unique removes duplicate values
"; $array=array(); $array=array_unique($names); foreach($array as $key => $value) { echo $key . "-". $value . "
"; } print('
'); rsort($array); print("rsort function sorts array in reverse order
"); foreach($array as $key => $value) { echo $key . "-". $value . "
"; } print('
array_pop($array) functions returns the last element
'); $lastelement=array_pop($array); print('
Last element='.$lastelement.'
'); print('
Array after caling array_pop($array): The last element removed

'); foreach($array as $key => $value) { echo $key . "-". $value . "
"; } array_push($array, "Chris", "Colin"); print('
Array after calling array_push($array, "Chris", "Colin") and print_r: Chris and Colin are added to the end of array

'); print_r($array); print('

array_rand($array) returns random array index
'); $random=array_rand($array); print('
print array element by random index
'); print('

Random element='.$array[$random].'
'); $string=implode($array); print("
Array imploded in string:
"); print($string); ?>