From 56d05862c1323635e32f4fe5509897f307f3f61a Mon Sep 17 00:00:00 2001 From: Egon Schmid Date: Sat, 15 Sep 2001 23:47:44 +0000 Subject: [PATCH] Whitespace and some typos. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@57584 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 202 ++++++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 92 deletions(-) diff --git a/functions/array.xml b/functions/array.xml index 25e81e536f..003843c32a 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -1,5 +1,5 @@ - + Array Functions Arrays @@ -91,8 +91,7 @@ print_r($array); which will display : -Array -( +Array ( [0] => 1 [1] => 1 [2] => 1 @@ -112,15 +111,14 @@ Array 1-based index with <function>array</function> - $firstquarter = array(1 => 'January', 'February', 'March'); - print_r($firstquarter); +$firstquarter = array(1 => 'January', 'February', 'March'); +print_r($firstquarter); which will display : -Array -( +Array ( [1] => 'January' [2] => 'February' [3] => 'March' @@ -225,7 +223,9 @@ $result = array_diff ($array1, $array2); array_filter - Filters elements of an array using a callback function + + Filters elements of an array using a callback function + Description @@ -250,11 +250,11 @@ $result = array_diff ($array1, $array2); <function>array_filter</function> example function odd($var) { - return ($var % 2 == 1); + return ($var % 2 == 1); } function even($var) { - return ($var % 2 == 0); + return ($var % 2 == 0); } $array1 = array ("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5); @@ -434,18 +434,19 @@ array_keys ($array); // returns array ("color", "size") those still using PHP 3. - Implementation of <function>array_keys</function> for PHP 3 - users + Implementation of <function>array_keys</function> for PHP 3 + users function array_keys ($arr, $term="") { $t = array(); while (list($k,$v) = each($arr)) { - if ($term && $v != $term) + if ($term && $v != $term) { continue; $t[] = $k; } return $t; + } } @@ -460,7 +461,9 @@ function array_keys ($arr, $term="") { array_map - Applies the callback to the elements of the given arrays + + Applies the callback to the elements of the given arrays + Description @@ -475,18 +478,18 @@ function array_keys ($arr, $term="") { - array_map returns an array - containing all the elements of arr1 - after applying the callback function to each one. - The number of parameters that the callback function accepts should - match the number of arrays passed to the array_map + array_map returns an array containing all + the elements of arr1 after applying the + callback function to each one. The number of parameters that the + callback function accepts should match the number of arrays + passed to the array_map <function>array_map</function> example function cube($n) { - return $n*$n*$n; + return $n*$n*$n; } $a = array(1, 2, 3, 4, 5); @@ -503,11 +506,11 @@ $b = array_map("cube", $a); <function>array_map</function> - using more arrays function show_Spanish($n, $m) { - return "The number $n is called $m in Spanish"; + return "The number $n is called $m in Spanish"; } function map_Spanish($n, $m) { - return array ($n => $m); + return array ($n => $m); } $a = array(1, 2, 3, 4, 5); @@ -518,8 +521,7 @@ $c = array_map("show_Spanish", $a, $b); print_r($c); // will output: -// Array -// ( +// Array ( // [0] => The number 1 is called uno in Spanish // [1] => The number 2 is called dos in Spanish // [2] => The number 3 is called tres in Spanish @@ -532,8 +534,7 @@ $d = array_map("map_Spanish", $a , $b); print_r($d); // will output: -// Array -// ( +// Array ( // [0] => Array // ( // [1] => uno @@ -577,7 +578,7 @@ print_r($d); - <function>array_map</function> - creating an array of arrays + Creating an array of arrays $a = array(1, 2, 3, 4, 5); $b = array("one", "two", "three", "four", "five"); @@ -1050,7 +1051,9 @@ print $input[$rand_keys[1]]."\n"; array array_reverse array array - bool preserve_keys + bool + preserve_keys + @@ -1070,8 +1073,9 @@ $result_keyed = array_reverse ($input, TRUE); - This makes both $result and $result_keyed - be array(array ("green", "red"), 4.0, "php"). But + This makes both $result and + $result_keyed be array(array + ("green", "red"), 4.0, "php"). But $result_keyed[0] is still "php". @@ -1087,7 +1091,8 @@ $result_keyed = array_reverse ($input, TRUE); array_reduce - Iteratively reduce the array to a single value using a callback function + Iteratively reduce the array to a single value using a callback + function @@ -1103,7 +1108,7 @@ $result_keyed = array_reverse ($input, TRUE); - array_reduce applies iteratively the + array_reduce applies iteratively the callback function to the elements of the array input, so as to reduce the array to a single value. If the optional intial is @@ -1115,13 +1120,13 @@ $result_keyed = array_reverse ($input, TRUE); <function>array_reduce</function> example function rsum($v, $w) { - $v += $w; - return $v; + $v += $w; + return $v; } function rmul($v, $w) { - $v *= $w; - return $v; + $v *= $w; + return $v; } $a = array(1, 2, 3, 4, 5); @@ -1135,8 +1140,8 @@ $d = array_reduce($x, "rsum", 1); This will result in $b containing 15, $c containing - 1200 (= 1*2*3*4*5*10), and $d - containing 1. + 1200 (= 1*2*3*4*5*10), and + $d containing 1. See also array_filter, @@ -1164,9 +1169,8 @@ $d = array_reduce($x, "rsum", 1); array_shift shifts the first value of the array off and returns it, shortening the array by one element and moving everything - down. - If array is empty (or is not an array), - &null; will be returned. + down. If array is empty (or is not an + array), &null; will be returned. @@ -1314,7 +1318,7 @@ $output = array_slice ($input, 0, 3); // returns "a", "b", and "c" The following equivalences hold: - + array_push ($input, $x, $y) array_splice ($input, count ($input), 0, array ($x, $y)) array_pop ($input) array_splice ($input, -1) @@ -1378,7 +1382,7 @@ array_splice ($input, -1, 1, array("black", "maroon")); <function>array_sum</function> examples -$a = array(2,4,6,8); +$a = array(2, 4, 6, 8); echo "sum(a) = ".array_sum($a)."\n"; // prints: sum(a) = 20 @@ -1554,8 +1558,8 @@ array_values ($array); // returns array ("XL", "gold") those still using PHP 3. - Implementation of <function>array_values</function> for PHP 3 - users + Implementation of <function>array_values</function> for PHP 3 + users function array_values ($arr) { @@ -1735,7 +1739,9 @@ c = apple void asort array array - int sort_flags + int + sort_flags + @@ -1833,8 +1839,9 @@ $location_vars = array ("city", "state"); $result = compact ("event", "nothing_here", $location_vars); - After this, $result will be array ("event" - => "SIGGRAPH", "city" => "San Francisco", "state" => "CA"). + After this, $result will be array + ("event" => "SIGGRAPH", "city" => "San Francisco", + "state" => "CA"). @@ -1876,9 +1883,9 @@ $result = compact ("event", "nothing_here", $location_vars); - Please see the Arrays - section of the manual for a detailed explanation of how arrays are - implemented and used in PHP. + Please see the Arrays + section of the manual for a detailed explanation of how arrays + are implemented and used in PHP. @@ -1960,7 +1967,8 @@ $result = count ($b); each - Return the current key and value pair from an array and advance the array cursor + Return the current key and value pair from an array and advance + the array cursor @@ -2115,10 +2123,11 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) { - extract checks each key to see whether if constitutes - a valid variable name and also for collisions with existing variables in - the symbol table. The way invalid/numeric keys and collisions are treated - is determined by extract_type. It can be one of the + extract checks each key to see whether if + constitutes a valid variable name and also for collisions with + existing variables in the symbol table. The way invalid/numeric + keys and collisions are treated is determined by + extract_type. It can be one of the following values: @@ -2150,8 +2159,9 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) { EXTR_PREFIX_ALL - Prefix all variable names with prefix. Since PHP - 4.0.5 this includes numeric ones as well. + Prefix all variable names with + prefix. Since PHP 4.0.5 this includes + numeric ones as well. @@ -2160,7 +2170,8 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) { Only prefix invalid/numeric variable names with - prefix. This flag has been added in PHP 4.0.5. + prefix. This flag has been added in + PHP 4.0.5. @@ -2172,13 +2183,14 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) { Note that prefix is only required if - extract_type is EXTR_PREFIX_SAME, EXTR_PREFIX_ALL, - or EXTR_PREFIX_INVALID. If the prefixed result is not a valid variable - name, it is not imported into the symbol table. + extract_type is EXTR_PREFIX_SAME, + EXTR_PREFIX_ALL, or EXTR_PREFIX_INVALID. If the prefixed result + is not a valid variable name, it is not imported into the symbol + table. - extract returns the number of variables successfully - imported into the symbol table. + extract returns the number of variables + successfully imported into the symbol table. A possible use for extract is to import into symbol table @@ -2266,9 +2278,9 @@ blue, large, sphere, medium <function>in_array</function> example $os = array ("Mac", "NT", "Irix", "Linux"); -if (in_array ("Irix", $os)){ +if (in_array ("Irix", $os)) { print "Got Irix"; - } +} @@ -2301,7 +2313,8 @@ if (in_array(1.13, $a, TRUE)) array_search - Searches the array for a given value and returns the corresponding key if successful + Searches the array for a given value and returns the + corresponding key if successful @@ -2549,8 +2562,8 @@ while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { <function>natsort</function> example -$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); - +$array1 = $array2 = array ("img12.png", "img10.png", "img2.png", "img1.png"); + sort($array1); echo "Standard sorting\n"; print_r($array1); @@ -2586,7 +2599,7 @@ Array ) - For more infomation see: Martin Pool's Natural Order String Comparison page. @@ -2765,29 +2778,29 @@ Array range returns an array of elements from low to high, - inclusive. If low > high, the sequence will be from high to - low. + inclusive. If low > high, the sequence will be from high to low. <function>range</function> examples -foreach(range(0,9) as $number) { - echo $number; +foreach(range(0, 9) as $number) { + echo $number; } -foreach(range('a','z') as $letter) { - echo $letter; +foreach(range('a', 'z') as $letter) { + echo $letter; } -foreach(range('z','a') as $letter) { - echo $letter; +foreach(range('z', 'a') as $letter) { + echo $letter; } - - - Prior to version 4.0.7 the range() function only generated incrementing integer arrays. - Support for character sequences and decrementing arrays was added in 4.0.7. - - + + + Prior to version 4.0.7 the range() function only generated + incrementing integer arrays. Support for character sequences + and decrementing arrays was added in 4.0.7. + + See shuffle for another example of its use. @@ -2935,7 +2948,8 @@ while (list (, $number) = each ($numbers)) { - The sizeof function is an alias for count. + The sizeof function is an alias for + count. See also count. @@ -2954,7 +2968,9 @@ while (list (, $number) = each ($numbers)) { void sort array array - int sort_flags + int + sort_flags + @@ -2962,7 +2978,7 @@ while (list (, $number) = each ($numbers)) { lowest to highest when this function has completed. <function>sort</function> example - + <?php $fruits = array ("lemon", "orange", "banana", "apple"); @@ -2994,7 +3010,7 @@ fruits[3] = orange The optional second parameter sort_flags - may be used to modify the sorting behavior using theese valies: + may be used to modify the sorting behavior using these values: Sorting type flags: @@ -3015,7 +3031,8 @@ fruits[3] = orange asort, ksort, natsort, natcasesort, rsort, usort, - array_multisort, and uksort. + array_multisort, and + uksort. @@ -3203,7 +3220,7 @@ while (list ($key, $value) = each ($a)) { function cmp ($a, $b) { - return strcmp($a["fruit"],$b["fruit"]); + return strcmp($a["fruit"], $b["fruit"]); } $fruits[0]["fruit"] = "lemons"; @@ -3244,8 +3261,9 @@ $fruits[2]: lemons - See also: uasort, uksort, - sort, asort, + See also: uasort, + uksort, sort, + asort, arsort,ksort, natsort, and rsort.