PHP

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

function is used to create an array.

A: array() S: index - array(value1, value2, value3, etc.) associative -array(key=>value,key=>value,key=>value,etc.) E: $cars=array("Volvo","BMW","Toyota");echo "I like " . $cars[0] . ", " . $cars[1] . " and " . $cars[2] . ".";

function changes all keys in an array to lowercase or uppercase.

A: array_change_key_case() S: array_change_key_case(array, case) E: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); print_r(array_change_key_case($age,CASE_UPPER));

function splits an array into chunks of new arrays.

A: array_chunk() S: array_chunk(array, size, preserve_key) E: $cars=array("Volvo","BMW","Toyota","Honda","Mercedes","Opel"); print_r(array_chunk($cars,2));

function returns the values from a single column in the input array.

A: array_column() S: array_column(array, column_key, index_key) E: // An array that represents a possible record set returned from a database$a = array(array('id' => 5698,'first_name' => 'Peter','last_name' => 'Griffin',),array('id' => 4767,'first_name' => 'Ben','last_name' => 'Smith',),array('id' => 3809,'first_name' => 'Joe','last_name' => 'Doe',));$last_names = array_column($a, 'last_name');print_r($last_names);

function creates an array by using the elements from one "keys" array and one "values" array.

A: array_combine() S: array_combine(keys, values) E: $fname=array("Peter","Ben","Joe");$age=array("35","37","43"); $c=array_combine($fname,$age);print_r($c);

function counts all the values of an array.

A: array_count_values() S: array_count_values(array) E: $a=array("A","Cat","Dog","A","Dog");print_r(array_count_values($a));

function compares the values of two (or more) arrays, and returns the differences.

A: array_diff() S: array_diff(array1, array2, array3, ...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue");$result=array_diff($a1,$a2);print_r($result);

function compares the keys and values of two (or more) arrays, and returns the differences.

A: array_diff_assoc() S: array_diff_assoc(array1,array2,array3...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("a"=>"red","b"=>"green","c"=>"blue");$result=array_diff_assoc($a1,$a2); print_r($result);

function compares the keys of two (or more) arrays, and returns the differences.

A: array_diff_key() S: array_diff_key(array1, array2, array3, ...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("a"=>"red","c"=>"blue","d"=>"pink"); $result=array_diff_key($a1,$a2);print_r($result);

function compares the keys and values of two (or more) arrays, and returns the differences. (use a user-defined function to compare the keys)

A: array_diff_uassoc() S: array_diff_uassoc(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b){if ($a===$b){return 0;}return ($a>$b)?1:-1;} $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("d"=>"red","b"=>"green","e"=>"blue"); $result=array_diff_uassoc($a1,$a2,"myfunction");print_r($result);

function compares the keys of two (or more) arrays, and returns the differences. (using a user-defined key comparison function)

A: array_diff_ukey() S: array_diff_ukey(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b){if ($a===$b){return 0;}return ($a>$b)?1:-1;} $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("a"=>"blue","b"=>"black","e"=>"blue"); $result=array_diff_ukey($a1,$a2,"myfunction");print_r($result);

function fills an array with values.

A: array_fill() S: array_fill(index, number, value) E: $a1=array_fill(3,4,"blue");print_r($a1);

function fills an array with values, specifying keys.

A: array_fill_keys() S: array_fill_keys(keys, value) E: $keys=array("a","b","c","d");$a1=array_fill_keys($keys,"blue"); print_r($a1);

function filters the values of an array using a callback function.

A: array_filter() S: array_filter(array, callbackfunction, flag) E: function test_odd($var){return($var & 1); }$a1=array(1,3,2,3,4);print_r(array_filter($a1,"test_odd"));

function flips/exchanges all keys with their associated values in an array.

A: array_flip() S: array_flip(array) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $result=array_flip($a1);print_r($result);

function compares the values of two (or more) arrays, and returns the matches.

A: array_intersect() S: array_intersect(array1, array2, array3, ...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue");$result=array_intersect($a1,$a2);print_r($result);

function compares the keys and values of two (or more) arrays, and returns the matches.

A: array_intersect_assoc() S: array_intersect_assoc(array1,array2,array3, ...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("a"=>"red","b"=>"green","c"=>"blue");$result=array_intersect_assoc($a1,$a2); print_r($result);

function compares the keys of two (or more) arrays, and returns the matches.

A: array_intersect_key() S: array_intersect_key(array1, array2, array3, ...) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("a"=>"red","c"=>"blue","d"=>"pink"); $result=array_intersect_key($a1,$a2);print_r($result);

function compares the keys and values of two (or more) arrays, and returns the matches. (using a user-defined key comparison function)

A: array_intersect_uassoc() S: array_intersect_uassoc(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b){if ($a===$b){return 0;}return ($a>$b)?1:-1;} $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("d"=>"red","b"=>"green","e"=>"blue"); $result=array_intersect_uassoc($a1,$a2,"myfunction");print_r($result);

function compares the keys of two (or more) arrays, and returns the matches. (using a user-defined key comparison function)

A: array_intersect_ukey() S: array_intersect_ukey(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b){if ($a===$b){return 0;}return ($a>$b)?1:-1;} $a1=array("a"=>"red","b"=>"green","c"=>"blue");$a2=array("a"=>"blue","b"=>"black","e"=>"blue"); $result=array_intersect_ukey($a1,$a2,"myfunction");print_r($result);

function checks an array for a specified key, and returns true if the key exists and false if the key does not exist.

A: array_key_exists() S: array_key_exists(key, array) E: $a=array("Volvo"=>"XC90","BMW"=>"X5");if (array_key_exists("Volvo",$a)){echo "Key exists!";}else{echo "Key does not exist!";}

function returns an array containing the keys.

A: array_keys() S: array_keys(array, value, strict) E: $a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander"); print_r(array_keys($a));

function sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function.

A: array_map() S: array_map(myfunction, array1, array2, array3, ...) E: function myfunction($v){return($v*$v);} $a=array(1,2,3,4,5); print_r(array_map("myfunction",$a));

function merges one or more arrays into one array.

A: array_merge() S: array_merge(array1, array2, array3, ...) E: $a1=array("red","green"); $a2=array("blue","yellow"); print_r(array_merge($a1,$a2));

function merges one or more arrays into one array. The difference between this function and the array_merge() function is when two or more array elements have the same key. Instead of override the keys, the [blank] function makes the value as an array.

A: array_merge_recursive() S: array_merge_recursive(array1, array2, array3, ...) E: $a1=array("a"=>"red","b"=>"green"); $a2=array("c"=>"blue","b"=>"yellow");print_r(array_merge_recursive($a1,$a2));

function returns a sorted array. You can assign one or more arrays. The function sorts the first array, and the other arrays follow, then, if two or more values are the same, it sorts the next array, and so on.

A: array_multisort() S: array_multisort(array1, sortorder, sorttype, array2, array3, ...) E: $a=array("Dog","Cat","Horse","Bear","Zebra");array_multisort($a); print_r($a);

function inserts a specified number of elements, with a specified value, to an array.

A: array_pad() S: array_pad(array, size, value) E: $a=array("red","green"); print_r(array_pad($a,5,"blue"));

function deletes the last element of an array.

A: array_pop() S: array_pop(array) E: $a=array("red","green","blue"); array_pop($a); print_r($a);

function calculates and returns the product of an array.

A: array_product() S: array_product(array) E: $a=array(5,5); echo(array_product($a));

function inserts one or more elements to the end of an array.

A: array_push() S: array_push(array, value1, value2, ...) E: $a=array("red","green"); array_push($a,"blue","yellow"); print_r($a);

function returns a random key from an array, or it returns an array of random keys if you specify that the function should return more than one key.

A: array_rand() S: array_rand(array, number) E: $a=array("red","green","blue","yellow","brown"); $random_keys=array_rand($a,3); echo $a[$random_keys[0]]."<br>"; echo $a[$random_keys[1]]."<br>"; echo $a[$random_keys[2]];

function sends the values in an array to a user-defined function, and returns a string.

A: array_reduce() S: array_reduce(array, myfunction, initial) E: function myfunction($v1,$v2) { return $v1 . "-" . $v2; } $a=array("Dog","Cat","Horse");print_r(array_reduce($a,"myfunction"));

function replaces the values of the first array with the values from following arrays.

A: array_replace() S: array_replace(array1, array2, array3, ...) E: $a1=array("red","green"); $a2=array("blue","yellow"); print_r(array_replace($a1,$a2));

function replaces the values of the first array with the values from following arrays recursively. You can assign one array to the function, or as many as you like.

A: array_replace_recursive() S: array_replace_recursive(array1, array2, array3, ...) E: $a1=array("a"=>array("red"),"b"=>array("green","blue"),); $a2=array("a"=>array("yellow"),"b"=>array("black"));print_r(array_replace_recursive($a1,$a2));

function returns an array in the reverse order.

A: array_reverse() S: array_reverse(array, preserve) E: $a=array("a"=>"Volvo","b"=>"BMW","c"=>"Toyota");print_r(array_reverse($a));

function search an array for a value and returns the key.

A: array_search() S: array_search(value, array, strict) E: $a=array("a"=>"red","b"=>"green","c"=>"blue"); echo array_search("red",$a);

function removes the first element from an array, and returns the value of the removed element.

A: array_shift() S: array_shift(array) E: $a=array("a"=>"red","b"=>"green","c"=>"blue"); echo array_shift($a); print_r ($a);

function returns selected parts of an array.

A: array_slice() S: array_slice(array, start, length, preserve) E: $a=array("red","green","blue","yellow","brown");print_r(array_slice($a,2));

function removes selected elements from an array and replaces it with new elements. The function also returns an array with the removed elements.

A: array_splice() S: array_splice(array, start, length, array) E: $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("a"=>"purple","b"=>"orange");array_splice($a1,0,2,$a2); print_r($a1);

function returns the sum of all the values in the array.

A: array_sum() S: array_sum(array) E: $a=array(5,15,25);echo array_sum($a);

function compares the values of two or more arrays, and returns the differences. (use a user-defined function to compare the values)

A: array_udiff() S: array_udiff(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b) { if ($a===$b) { return 0; }return ($a>$b)?1: 1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"blue","b"=>"black","e"=>"blue"); $result=array_udiff($a1,$a2,"myfunction"); print_r($result);

function compares the keys and values of two or more arrays, and returns the differences. (using a built-in function to compare the keys and a user-defined function to compare the values)

A: array_udiff_assoc() S: array_udiff_assoc(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","b"=>"blue","c"=>"green"); $result=array_udiff_assoc($a1,$a2,"myfunction"); print_r($result);

function compares the keys and values of two or more arrays, and returns the differences. (using two user-defined functions for comparison)

A: array_udiff_uassoc() S: array_udiff_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value) E: function myfunction_key($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } function myfunction_value($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","b"=>"green","c"=>"green"); $result=array_udiff_uassoc($a1,$a2,"myfunction_value","myfunction_key"); print_r($result);

function compares the values of two or more arrays, and returns the matches. (use a user-defined function to compare the values)

A: array_uintersect() S: array_uintersect(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"blue","b"=>"black","e"=>"blue"); $result=array_uintersect($a1,$a2,"myfunction"); print_r($result);

function compares the keys and values of two or more arrays, and returns the matches. (using a built-in function to compare the keys and a user-defined function to compare the values)

A: array_uintersect_assoc() S: array_uintersect_assoc(array1, array2, array3, ..., myfunction) E: function myfunction($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","b"=>"blue","c"=>"green"); $result=array_uintersect_assoc($a1,$a2,"myfunction"); print_r($result);

function compares the keys and values of two or more arrays, and returns the matches. (using two user-defined functions for comparison)

A: array_uintersect_uassoc() S: array_uintersect_uassoc(array1, array2, array3, ..., myfunc_key, myfunc_value) E: function myfunction_key($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } function myfunction_value($a,$b) { if ($a===$b) { return 0; } return ($a>$b)?1:-1; } $a1=array("a"=>"red","b"=>"green","c"=>"blue"); $a2=array("a"=>"red","b"=>"green","c"=>"green"); $result=array_uintersect_uassoc($a1,$a2,"myfunction_key","myfunction_value"); print_r($result);

function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed.

A: array_unique() S: array_unique(array, sorttype) E: $a=array("a"=>"red","b"=>"green","c"=>"red");print_r(array_unique($a));

function inserts new elements to an array. The new array values will be inserted in the beginning of the array.

A: array_unshift() S: array_unshift(array, value1, value2, value3, ...) E: $a=array("a"=>"red","b"=>"green");array_unshift($a,"blue"); print_r($a);

function returns an array containing all the values of an array.

A: array_values() S: array_values(array) E: $a=array("Name"=>"Peter","Age"=>"41","Country"=>"USA");print_r(array_values($a));

function runs each array element in a user-defined function. The array's keys and values are parameters in the function.

A: array_walk() S: array_walk(array, myfunction, parameter...) E: function myfunction($value,$key) { echo "The key $key has the value $value<br>"; } $a=array("a"=>"red","b"=>"green","c"=>"blue");array_walk($a,"myfunction");

function runs each array element in a user-defined function. The array's keys and values are parameters in the function. The difference between this function and the array_walk() function is that with this function you can work with deeper arrays (an array inside an array).

A: array_walk_recursive() S: array_walk_recursive(array, myfunction, parameter...) E: function myfunction($value,$key) { echo "The key $key has the value $value<br>"; } $a1=array("a"=>"red","b"=>"green"); $a2=array($a1,"1"=>"blue","2"=>"yellow");array_walk_recursive($a2,"myfunction");

function sorts an associative array in descending order, according to the value.

A: arsort() S: arsort(array, sorttype) E: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); arsort($age);

function sorts an associative array in ascending order, according to the value.

A: asort() S: asort(array, sorttype) E: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); asort($age);

function creates an array from variables and their values.

A: compact() S: compact(var1, var2...) E: $firstname = "Peter"; $lastname = "Griffin"; $age = "41"; $result = compact("firstname", "lastname", "age"); print_r($result);

function returns the number of elements in an array.

A: count() S: count(array, mode) E: $cars=array("Volvo","BMW","Toyota"); echo count($cars);

function returns the value of the current element in an array.

A: current() S: current(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br>";

function returns the current element key and value, and moves the internal pointer forward.

A: each() S: each(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); print_r (each($people));

function moves the internal pointer to, and outputs, the last element in the array.

A: end() S: end(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br>"; echo end($people);

function imports variables into the local symbol table from an array.

A: extract() S: extract(array, extract_rules, prefix) E: $a = "Original"; $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse"); extract($my_array); echo "\$a = $a; \$b = $b; \$c = $c";

function searches an array for a specific value.

A: in_array() S: in_array(search, array, type) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); if (in_array("Glenn", $people)) { echo "Match found"; } else { echo "Match not found"; }

function returns the element key from the current internal pointer position.

A: key() S: key(array) E: $people=array("Peter","Joe","Glenn","Cleveland"); echo "The key from the current position is: " . key($people);

function sorts an associative array in descending order, according to the key.

A: krsort() S: krsort(array, sorttype) E: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); krsort($age);

function sorts an associative array in ascending order, according to the key.

A: ksort() S: ksort(array, sorttype) E: $age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43"); ksort($age);

function is used to assign values to a list of variables in one operation.

A: list() S: list(var1, var2, . . . ) E: $my_array = array("Dog","Cat","Horse"); list($a, $b, $c) = $my_array; echo "I have several animals, a $a, a $b and a $c.";

function sorts an array by using a "natural order" algorithm. The values keep their original keys. This function is case-insensitive.

A: natcasesort() S: natcasesort(array) E: $temp_files = array("temp15.txt","Temp10.txt","temp1.txt","Temp22.txt","temp2.txt"); natsort($temp_files); echo "Natural order: "; print_r($temp_files);echo "<br />"; natcasesort($temp_files); echo "Natural order case insensitve: "; print_r($temp_files); OUTPUT: Natural order: Array ( [0] => Temp10.txt [1] => Temp22.txt [2] => temp1.txt [4] => temp2.txt [3] => temp15.txt ) Natural order case insensitve: Array ( [2] => temp1.txt [4] => temp2.txt [0] => Temp10.txt [3] => temp15.txt [1] => Temp22.txt )

function sorts an array by using a "natural order" algorithm. The values keep their original keys.

A: natsort() S: natsort(array) E: $temp_files = array("temp15.txt","temp10.txt", "temp1.txt","temp22.txt","temp2.txt"); sort($temp_files); echo "Standard sorting: "; print_r($temp_files); echo "<br>"; natsort($temp_files);echo "Natural order: "; print_r($temp_files);

function moves the internal pointer to, and outputs, the next element in the array.

A: next() S: next(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br>"; echo next($people);

function returns the value of the current element in an array. This function is an alias of the current() function.

A: pos() S: pos(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo pos($people) . "<br>";

function moves the internal pointer to, and outputs, the previous element in the array

A: prev() S: prev(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br>"; echo next($people) . "<br>"; echo prev($people);

function creates an array containing a range of elements. This function returns an array of elements from low to high.

A: range() S: range(low, high, step) E: $number = range(0,5); print_r ($number);

function moves the internal pointer to the first element of the array.

A: reset() S: reset(array) E: $people = array("Peter", "Joe", "Glenn", "Cleveland"); echo current($people) . "<br>"; echo next($people) . "<br>"; echo reset($people);

function sorts an indexed array in descending order.

A: rsort() S: rsort(array, sorttype) E: $cars=array("Volvo","BMW","Toyota"); rsort($cars);

function randomizes the order of the elements in the array.

A: shuffle() S: shuffle(array) E: $my_array = array("red","green","blue","yellow","purple"); shuffle($my_array); print_r($my_array);

function returns the number of elements in an array. function is an alias of the count() function.

A: sizeof() S: sizeof(array, mode) E: $cars=array("Volvo","BMW","Toyota"); echo sizeof($cars);

function sorts an indexed array in ascending order. (alphabetical order)

A: sort() S: sort(array, sorttype) E: $cars=array("Volvo","BMW","Toyota"); sort($cars);

function sorts an array by values using a user-defined comparison function.

A: uasort() S: uasort(array, myfunction) E: function my_sort($a,$b) { if ($a==$b) return 0; return ($a<$b)?-1:1; } $arr=array("a"=>4,"b"=>2,"c"=>8,"d"=>6); uasort($arr,"my_sort");

function sorts an array by keys using a user-defined comparison function.

A: uksort() S: uksort(array, myfunction) E: function my_sort($a,$b) { if ($a==$b) return 0; return ($a<$b)?-1:1; } $arr=array("a"=>4,"b"=>2,"c"=>8,"d"=>6); uksort($arr,"my_sort");

function sorts an array using a user-defined comparison function.

A: usort() S: usort(array, myfunction) E: function my_sort($a,$b) { if ($a==$b) return 0; return ($a<$b)?-1:1; } $a=array(4,2,8,6); usort($a,"my_sort");


Set pelajaran terkait

Grado 12: comentarios después de los orales

View Set

PSCI 427: Ch. 11: Products Liability

View Set

Module 2 Chapter 28 Care of Patients Requiring Oxygen Therapy or Tracheostomy

View Set

ACCT 423 Final - International Auditing/Corp Governance

View Set

Adaptive Quizzing for the NCLEX-RN Exam - Ethics

View Set