Index: phpdoc/it/Translators
diff -u phpdoc/it/Translators:1.19 phpdoc/it/Translators:1.20
--- phpdoc/it/Translators:1.19 Wed Mar 7 02:31:34 2001
+++ phpdoc/it/Translators Mon Mar 26 08:16:38 2001
@@ -61,7 +61,7 @@
------- functions -----------------------------------------------------------
adabas.xml
apache.xml Gianluca Balbo assegnato
-array.xml
+array.xml Marco Cucinato assegnato
aspell.xml
bc.xml
calendar.xml
@@ -101,7 +101,7 @@
mysql.xml Cesare D'Amico assegnato
network.xml Carlo Valente assegnato
nis,xml
-oci8.xml Cucinato assegnato
+oci8.xml Cucinato tradotto
oracle.xml Cucinato tradotto
pcre.xml
pdf.xml
Index: phpdoc/it/functions/array.xml
diff -u phpdoc/it/functions/array.xml:1.6 phpdoc/it/functions/array.xml:1.7
--- phpdoc/it/functions/array.xml:1.6 Thu Aug 31 09:00:21 2000
+++ phpdoc/it/functions/array.xml Mon Mar 26 08:16:39 2001
@@ -13,6 +13,11 @@
There are specific database handling functions for populating
arrays from database queries, and several functions return arrays.
+
+ See also is_array, explode,
+ implode, split
+ and join.
+
@@ -45,6 +50,14 @@
+ Syntax "index => values", separated by commas, define index
+ and values. index may be of type string or numeric. When index is
+ omitted, a integer index is automatically generated, starting
+ at 0. If index is an integer, next generated index will
+ be the biggest integer index + 1. Note that when two identical
+ index are defined, the last overwrite the first.
+
+
The following example demonstrates how to create a
two-dimensional array, how to specify keys for associative
arrays, and how to skip-and-continue numeric indices in normal
@@ -53,14 +66,62 @@
Array example
$fruits = array (
- "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"),
- "numbers" => array (1, 2, 3, 4, 5, 6),
- "holes" => array ("first", 5 => "second", "third")
+ "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"),
+ "numbers" => array (1, 2, 3, 4, 5, 6),
+ "holes" => array ("first", 5 => "second", "third")
);
+
+ Automatic index with Array
+
+$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13);
+print_r($array);
+
+
+ which will display :
+
+
+Array
+(
+ [0] => 1
+ [1] => 1
+ [2] => 1
+ [3] => 13
+ [4] => 1
+ [8] => 1
+ [9] => 19
+)
+
+
+ Note that index '3' is defined twice, and keep its final value of 13.
+ Index 4 is defined after index 8, and next generated index (value 19)
+ is 9, since biggest index was 8.
+
+
+ This example creates a 1-based array.
+
+ 1-based index with Array
+
+ $firstquarter = array(1 => 'January', 'February', 'March');
+ print_r($firstquarter);
+
+
+ which will display :
+
+
+Array
+(
+ [1] => 'January'
+ [2] => 'February'
+ [3] => 'March'
+)
+
+
+
+
See also: list.
@@ -89,7 +150,7 @@
Array_count_values example
$array = array (1, "hello", 1, "world", "hello");
-array_count_values ($array); // returns array (1=>2, "hello"=>2, "world"=>1)
+array_count_values ($array); // returns array (1=>2, "hello"=>2, "world"=>1)
@@ -123,8 +184,8 @@
Array_diff example
-$array1 = array ("a" => "green", "red", "blue");
-$array2 = array ("b" => "green", "yellow", "red");
+$array1 = array ("a" => "green", "red", "blue");
+$array2 = array ("b" => "green", "yellow", "red");
$result = array_diff ($array1, $array2);
@@ -194,15 +255,15 @@
Array_intersect example
-$array1 = array ("a" => "green", "red", "blue");
-$array2 = array ("b" => "green", "yellow", "red");
+$array1 = array ("a" => "green", "red", "blue");
+$array2 = array ("b" => "green", "yellow", "red");
$result = array_intersect ($array1, $array2);
This makes $result have array ("a"
- => "green", "red");
+ => "green", "red");
See also array_diff.
@@ -241,14 +302,40 @@
Array_keys example
-$array = array (0 => 100, "color" => "red");
+$array = array (0 => 100, "color" => "red");
array_keys ($array); // returns array (0, "color")
$array = array ("blue", "red", "green", "blue", "blue");
array_keys ($array, "blue"); // returns array (0, 3, 4)
+
+$array = array ("color" => array("blue", "red", "green"), "size" => array("small", "medium", "large"));
+array_keys ($array); // returns array ("color", "size")
+
+
+ This function was added to PHP 4, below is an implementation for
+ those still using PHP 3.
+
+
+ Implementation of array_keys for PHP 3
+ users
+
+
+function array_keys ($arr, $term="") {
+ $t = array();
+ while (list($k,$v) = each($arr)) {
+ if ($term && $v != $term)
+ continue;
+ $t[] = $k;
+ }
+ return $t;
+}
+
+
+
+
See also array_values.
@@ -287,15 +374,15 @@
array_merge example
-$array1 = array ("color" => "red", 2, 4);
-$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
+$array1 = array ("color" => "red", 2, 4);
+$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4);
array_merge ($array1, $array2);
- Resulting array will be array("color" => "green", 2, 4,
- "a", "b", "shape" => "trapezoid", 4).
+ Resulting array will be array("color" => "green", 2, 4,
+ "a", "b", "shape" => "trapezoid", 4).
See also array_merge_recursive.
@@ -337,15 +424,15 @@
Array_merge_recursive example
-$ar1 = array ("color" => array ("favorite" => "red"), 5);
-$ar2 = array (10, "color" => array ("favorite" => "green", "blue"));
+$ar1 = array ("color" => array ("favorite" => "red"), 5);
+$ar2 = array (10, "color" => array ("favorite" => "green", "blue"));
$result = array_merge_recursive ($ar1, $ar2);
- Resulting array will be array ("color" => array
- ("favorite" => array ("red", "green"), "blue"), 5, 10).
+ Resulting array will be array ("color" => array
+ ("favorite" => array ("red", "green"), "blue"), 5, 10).
See also array_merge.
@@ -425,7 +512,8 @@
SORT_REGULAR after before each new array argument.
- Returns true on success, false on failure.
+ Returns TRUE on success, FALSE
+ on failure.
@@ -526,7 +614,9 @@
Array_pop pops and returns the last value of
the array, shortening the
- array by one element.
+ array by one element.
+ If array is empty (or is not an array),
+ NULL will be returned.
@@ -667,12 +757,14 @@
array array_reversearray array
+ bool preserve_keysArray_reverse takes input
array and returns a new array with the
- order of the elements reversed.
+ order of the elements reversed, preserving the keys if
+ preserve_keys is TRUE.
@@ -680,13 +772,21 @@
$input = array ("php", 4.0, array ("green", "red"));
$result = array_reverse ($input);
+$result_keyed = array_reverse ($input, TRUE);
This makes $result have array
- (array ("green", "red"), 4.0, "php").
+ (array ("green", "red"), 4.0, "php"). But
+ $result2[0] is still
+ "php".
+
+
+ The second parameter was added in PHP 4.0.3.
+
+
@@ -710,6 +810,8 @@
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.
@@ -890,6 +992,42 @@
+
+
+
+ array_sum
+
+ Calculate the sum of values in an array.
+
+
+
+ Description
+
+
+ mixed array_sum
+ array arr
+
+
+
+ Array_sum returns the sum of values
+ in an array as an integer or float.
+
+
+
+ Array_sum examples
+
+$a = array(2,4,6,8);
+echo "sum(a) = ".array_sum($a)."\n";
+// prints: sum(a) = 20
+
+$b = array("a"=>1.2,"b"=>2.3,"c"=>3.4);
+echo "sum(b) = ".array_sum($b)."\n";
+// prints: sum(b) = 6.9
+
+
+
+
+
@@ -914,14 +1052,14 @@
Array_unique example
-$input = array ("a" => "green", "red", "b" => "green", "blue", "red");
+$input = array ("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique ($input);
- This makes $result have array ("a" =>
- "green", "red", "blue");
+ This makes $result have array ("a" =>
+ "green", "red", "blue");.
@@ -992,18 +1130,39 @@
- Array_values returns all the values from the
+ array_values returns all the values from the
input array.
Array_values example
-$array = array ("size" => "XL", "color" => "gold");
+$array = array ("size" => "XL", "color" => "gold");
array_values ($array); // returns array ("XL", "gold")
+
+
+ This function was added to PHP 4, below is an implementation for
+ those still using PHP 3.
+
+
+ Implementation of array_values for PHP 3
+ users
+
+
+function array_values ($arr) {
+ $t = array();
+ while (list($k, $v) = each ($arr)) {
+ $t[] = $v;
+ return $t;
+ }
+}
+
+
+
+
@@ -1065,14 +1224,14 @@
Array_walk example
-$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
+$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
function test_alter (&$item1, $key, $prefix) {
- $item1 = "$prefix: $item1";
+ $item1 = "$prefix: $item1";
}
function test_print ($item2, $key) {
- echo "$key. $item2<br>\n";
+ echo "$key. $item2<br>\n";
}
array_walk ($fruits, 'test_print');
@@ -1115,7 +1274,7 @@
Arsort example
-$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
+$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
arsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
@@ -1175,7 +1334,7 @@
Asort example
-$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
+$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
@@ -1247,6 +1406,9 @@
It returns the output array with all the variables added to it.
+ Any strings that are not set will simply be skipped.
+
+ Compact example
@@ -1256,11 +1418,11 @@
$location_vars = array ("city", "state");
-$result = compact ("event", $location_vars);
+$result = compact ("event", "nothing_here", $location_vars);
After this, $result will be array ("event"
- => "SIGGRAPH", "city" => "San Francisco", "state" => "CA").
+ => "SIGGRAPH", "city" => "San Francisco", "state" => "CA").
@@ -1303,6 +1465,18 @@
+
+ Count example
+
+$a[0] = 1;
+$a[1] = 3;
+$a[2] = 5;
+$result = count ($a);
+//$result == 3
+
+
+
+
See also: sizeof,
isset, and
is_array.
@@ -1333,15 +1507,15 @@
array element that's currently being pointed by the internal
pointer. It does not move the pointer in any way. If the
internal pointer points beyond the end of the elements list,
- current returns false.
+ current returns FALSE.
If the array contains empty elements (0 or "", the empty
- string) then this function will return false for these elements
- as well. This makes it impossible to determine if you are
- really at the end of the list in such an array using
- current. To properly traverse an array
- that may contain empty elements, use the
+ string) then this function will return FALSE
+ for these elements as well. This makes it impossible to
+ determine if you are really at the end of the list in such
+ an array using current. To properly
+ traverse an array that may contain empty elements, use the
each function.
@@ -1381,7 +1555,8 @@
If the internal pointer for the array points past the end of the
- array contents, each returns false.
+ array contents, each returns
+ FALSE.
@@ -1394,13 +1569,13 @@
$bar now contains the following key/value
pairs:
- 0 => 0
- 1 => 'bob'
- key => 0
- value => 'bob'
+ 0 => 0
+ 1 => 'bob'
+ key => 0
+ value => 'bob'
-$foo = array ("Robert" => "Bob", "Seppo" => "Sepi");
+$foo = array ("Robert" => "Bob", "Seppo" => "Sepi");
$bar = each ($foo);
@@ -1408,10 +1583,10 @@
$bar now contains the following key/value
pairs:
- 0 => 'Robert'
- 1 => 'Bob'
- key => 'Robert'
- value => 'Bob'
+ 0 => 'Robert'
+ 1 => 'Bob'
+ key => 'Robert'
+ value => 'Bob'
@@ -1429,7 +1604,7 @@
echo "Values submitted via POST method:<br>";
reset ($HTTP_POST_VARS);
while (list ($key, $val) = each ($HTTP_POST_VARS)) {
- echo "$key => $val<br>";
+ echo "$key => $val<br>";
}
@@ -1458,13 +1633,13 @@
Description
- end
+ mixed endarray arrayEnd advances array's
- internal pointer to the last element.
+ internal pointer to the last element, and returns that element.
See also: current,
@@ -1485,7 +1660,7 @@
Description
- void extract
+ int extractarray var_arrayint
extract_type
@@ -1504,43 +1679,60 @@
extract_type and
prefix parameters.
+
+
+ Since version 4.0.5 this function returns the number of
+ variables extracted.
+
+
- Extract checks for colissions with existing
- variables. The way 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:
EXTR_OVERWRITE
-
- If there is a collision, overwrite the existing variable.
-
+
+ If there is a collision, overwrite the existing variable.
+ EXTR_SKIP
-
- If there is a collision, don't overwrite the existing
- variable.
-
+
+ If there is a collision, don't overwrite the existing
+ variable.
+ EXTR_PREFIX_SAME
- If there is a collision, prefix the new variable with
- prefix.
-
+ If there is a collision, prefix the variable name with
+ prefix.
+ EXTR_PREFIX_ALL
+
+
+ Prefix all variable names with prefix. Since PHP
+ 4.0.5 this includes numeric ones as well.
+
+
+
+
+ EXTR_PREFIX_INVALID
-
- Prefix all variables with prefix.
-
+
+ Only prefix invalid/numeric variable names with
+ prefix. This flag has been added in PHP 4.0.5.
+
@@ -1551,13 +1743,13 @@
Note that prefix is only required if
- extract_type is EXTR_PREFIX_SAME or
- EXTR_PREFIX_ALL.
+ 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 checks each key to see if it
- constitues a valid variable name, and if it does only then does
- it proceed to import it.
+ extract returns the number of variables successfully
+ imported into the symbol table.
A possible use for extract is to import into symbol table
@@ -1568,15 +1760,15 @@
Extract example
-<php?
+<?php
/* Suppose that $var_array is an array returned from
wddx_deserialize */
$size = "large";
-$var_array = array ("color" => "blue",
- "size" => "medium",
- "shape" => "sphere");
+$var_array = array ("color" => "blue",
+ "size" => "medium",
+ "shape" => "sphere");
extract ($var_array, EXTR_PREFIX_SAME, "wddx");
print "$color, $size, $shape, $wddx_size\n";
@@ -1602,13 +1794,20 @@
$wddx_size, and
$wddx_shape.
+
+ You must use an associative array, a numerically indexed array
+ will not produce results.
+
+
+ See also: compact.
+ in_array
- Return true if a value exists in an array
+ Return TRUE if a value exists in an arrayDescription
@@ -1617,23 +1816,87 @@
bool in_arraymixed needlearray haystack
+ bool strict
Searches haystack for
- needle and returns true if it is found in
- the array, false otherwise.
+ needle and returns TRUE
+ if it is found in the array, FALSE otherwise.
+ If the third parameter strict is set to
+ TRUE then the in_array
+ will also check the types of the needle
+ in the haystack.
+
+ In_array example
$os = array ("Mac", "NT", "Irix", "Linux");
-if (in_array ("Irix", $os))
+if (in_array ("Irix", $os)){
print "Got Irix";
+ }
+
+
+ In_array with strict example
+
+
+
+// This will output:
+
+1.13 found with strict check
+
+
+
+
+ See also array_search.
+
+
+
+
+
+
+ array_search
+
+ Searches the array for a given value and returns the corresponding key if successful
+
+
+
+ Description
+
+
+ mixed array_search
+ mixed needle
+ array haystack
+ bool strict
+
+
+
+ Searches haystack for
+ needle and returns the key if it is found in
+ the array, FALSE otherwise.
+
+
+ If the third parameter strict is set to
+ TRUE then the array_search
+ will also check the types of the needle
+ in the haystack.
+
+
+ See also in_array.
+
@@ -1682,11 +1945,11 @@
Krsort example
-$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
+$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
krsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
- echo "$key -> $val\n";
+ echo "$key -> $val\n";
}
@@ -1739,11 +2002,11 @@
Ksort example
-$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
+$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
- echo "$key -> $val\n";
+ echo "$key -> $val\n";
}
@@ -1771,6 +2034,11 @@
sort, natsort, and
rsort.
+
+
+ The second parameter was added in PHP 4.
+
+
@@ -1871,19 +2139,19 @@
Standard sorting
Array
(
- [0] => img1.png
- [1] => img10.png
- [2] => img12.png
- [3] => img2.png
+ [0] => img1.png
+ [1] => img10.png
+ [2] => img12.png
+ [3] => img2.png
)
Natural order sorting
Array
(
- [3] => img1.png
- [2] => img2.png
- [1] => img10.png
- [0] => img12.png
+ [3] => img1.png
+ [2] => img2.png
+ [1] => img10.png
+ [0] => img12.png
)
@@ -1956,7 +2224,8 @@
Returns the array element in the next place that's pointed by the
- internal array pointer, or false if there are no more elements.
+ internal array pointer, or FALSE if
+ there are no more elements.
Next behaves like
@@ -1965,13 +2234,13 @@
element. That means it returns the next array element and
advances the internal array pointer by one. If advancing the
internal array pointer results in going beyond the end of the
- element list, next returns false.
+ element list, next returns FALSE.
If the array contains empty elements, or elements that have a key
- value of 0 then this function will return false for these elements
- as well. To properly traverse an array which may contain empty
- elements or elements with key values of 0 see the
+ value of 0 then this function will return FALSE
+ for these elements as well. To properly traverse an array which
+ may contain empty elements or elements with key values of 0 see the
each function.
@@ -2023,14 +2292,14 @@
Returns the array element in the previous place that's pointed by
- the internal array pointer, or false if there are no more
+ the internal array pointer, or FALSE if there are no more
elements.
If the array contains empty elements then this function will
- return false for these elements as well. To properly traverse
- an array which may contain empty elements see the
- each function.
+ return FALSE for these elements as well.
+ To properly traverse an array which may contain empty elements
+ see the each function.
@@ -2129,7 +2398,7 @@
rsort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
- echo "$key -> $val\n";
+ echo "$key -> $val\n";
}
@@ -2178,12 +2447,13 @@
This function shuffles (randomizes the order of the elements in)
- an array.
+ an array. You must use srand to seed this
+ function.
Shuffle example
$numbers = range (1,20);
-srand (time());
+srand ((double)microtime()*1000000);
shuffle ($numbers);
while (list (, $number) = each ($numbers)) {
echo "$number ";
@@ -2240,13 +2510,17 @@
lowest to highest when this function has completed.
Sort example
-
+
+<?php
+
$fruits = array ("lemon", "orange", "banana", "apple");
sort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
- echo "$key -> $val\n";
+ echo "fruits[".$key."] = ".$val;
}
+
+?>
@@ -2287,9 +2561,15 @@
See also: arsort,
asort, ksort,
- natsort,rsort,
- and usort.
+ natsort, natcasesort,
+ rsort, usort,
+ array_multisort, and uksort.
+
+
+ The second parameter was added in PHP 4.
+
+
@@ -2364,7 +2644,7 @@
return ($a > $b) ? -1 : 1;
}
-$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
+$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten");
uksort ($a, "cmp");