From 73f8077451999fc667bc774400961f1ae796fbf5 Mon Sep 17 00:00:00 2001 From: Ron Chmara Date: Wed, 18 Oct 2000 05:46:56 +0000 Subject: [PATCH] updating/expanding as per errata. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@34041 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/array.xml | 55 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/functions/array.xml b/functions/array.xml index f14dab52a4..bc903eb04d 100644 --- a/functions/array.xml +++ b/functions/array.xml @@ -1295,6 +1295,9 @@ fruits[a] = orange In short, it does the opposite of extract. It returns the output array with all the variables added to it. + + Any strings that are not set will simply be skipped. + <function>Compact</function> example @@ -1305,7 +1308,7 @@ $event = "SIGGRAPH"; $location_vars = array ("city", "state"); -$result = compact ("event", $location_vars); +$result = compact ("event", "nothing_here", $location_vars); After this, $result will be array ("event" @@ -1351,6 +1354,27 @@ $result = compact ("event", $location_vars); + + + <function>Count</function> example + +$a[0] = 1; +$a[1] = 3; +$a[2] = 5; +$result = count ($a); +//$result == 3, not 2, as there are 3 assigned elements + +$a[2] = 1; +$a[4] = ""; +$a[6] = 5; +$a[8] = 7; +$a[10] = 11; +$a[12] = ""; +$result = count ($a); +// $result == 4, as there are 4 assigned elements + + + See also: sizeof, isset, and @@ -1651,6 +1675,13 @@ blue, large, sphere, medium $wddx_size, and $wddx_shape. + + You must use an associative array, a numerically indexed array + will not produce results. + + + See also: compact. + @@ -1678,8 +1709,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"; + } @@ -1820,6 +1852,11 @@ fruits[d] = lemon sort, natsort, and rsort. + + + The second parameter was added in PHP 4. + + @@ -2227,12 +2264,13 @@ fruits[3] = apple This function shuffles (randomizes the order of the elements in) - an array. + an array. You must use srand to seed this + function. <function>Shuffle</function> example $numbers = range (1,20); -srand (time()); +srand ((double)microtime()*1000000); shuffle ($numbers); while (list (, $number) = each ($numbers)) { echo "$number "; @@ -2341,9 +2379,14 @@ fruits[3] = orange See also: arsort, asort, ksort, natsort, natcasesort, - rsort, usort - and uksort. + rsort, usort, + array_multisort, and uksort. + + + The second parameter was added in PHP 4. + +