mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Whitespace and some typos.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@57584 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
be771f02c9
commit
56d05862c1
1 changed files with 110 additions and 92 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.95 $ -->
|
||||
<!-- $Revision: 1.96 $ -->
|
||||
<reference id="ref.array">
|
||||
<title>Array Functions</title>
|
||||
<titleabbrev>Arrays</titleabbrev>
|
||||
|
@ -91,8 +91,7 @@ print_r($array);
|
|||
which will display :
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
Array
|
||||
(
|
||||
Array (
|
||||
[0] => 1
|
||||
[1] => 1
|
||||
[2] => 1
|
||||
|
@ -112,15 +111,14 @@ Array
|
|||
<example>
|
||||
<title>1-based index with <function>array</function></title>
|
||||
<programlisting role="php">
|
||||
$firstquarter = array(1 => 'January', 'February', 'March');
|
||||
print_r($firstquarter);
|
||||
$firstquarter = array(1 => 'January', 'February', 'March');
|
||||
print_r($firstquarter);
|
||||
</programlisting>
|
||||
</example>
|
||||
which will display :
|
||||
<informalexample>
|
||||
<programlisting>
|
||||
Array
|
||||
(
|
||||
Array (
|
||||
[1] => 'January'
|
||||
[2] => 'February'
|
||||
[3] => 'March'
|
||||
|
@ -225,7 +223,9 @@ $result = array_diff ($array1, $array2);
|
|||
<refentry id="function.array-filter">
|
||||
<refnamediv>
|
||||
<refname>array_filter</refname>
|
||||
<refpurpose>Filters elements of an array using a callback function</refpurpose>
|
||||
<refpurpose>
|
||||
Filters elements of an array using a callback function
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
@ -250,11 +250,11 @@ $result = array_diff ($array1, $array2);
|
|||
<title><function>array_filter</function> example</title>
|
||||
<programlisting role="php">
|
||||
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.
|
||||
<example>
|
||||
<title>
|
||||
Implementation of <function>array_keys</function> for PHP 3
|
||||
users
|
||||
Implementation of <function>array_keys</function> for PHP 3
|
||||
users
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
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;
|
||||
}
|
||||
}
|
||||
</programlisting>
|
||||
</example>
|
||||
|
@ -460,7 +461,9 @@ function array_keys ($arr, $term="") {
|
|||
<refentry id="function.array-map">
|
||||
<refnamediv>
|
||||
<refname>array_map</refname>
|
||||
<refpurpose>Applies the callback to the elements of the given arrays</refpurpose>
|
||||
<refpurpose>
|
||||
Applies the callback to the elements of the given arrays
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
|
@ -475,18 +478,18 @@ function array_keys ($arr, $term="") {
|
|||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
<function>array_map</function> returns an array
|
||||
containing all the elements of <parameter>arr1</parameter>
|
||||
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 <function>array_map</function>
|
||||
<function>array_map</function> returns an array containing all
|
||||
the elements of <parameter>arr1</parameter> 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 <function>array_map</function>
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>array_map</function> example</title>
|
||||
<programlisting role="php">
|
||||
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);
|
|||
<title><function>array_map</function> - using more arrays</title>
|
||||
<programlisting role="php">
|
||||
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);
|
|||
</para>
|
||||
<para>
|
||||
<example>
|
||||
<title><function>array_map</function> - creating an array of arrays</title>
|
||||
<title>Creating an array of arrays</title>
|
||||
<programlisting role="php">
|
||||
$a = array(1, 2, 3, 4, 5);
|
||||
$b = array("one", "two", "three", "four", "five");
|
||||
|
@ -1050,7 +1051,9 @@ print $input[$rand_keys[1]]."\n";
|
|||
<funcprototype>
|
||||
<funcdef>array <function>array_reverse</function></funcdef>
|
||||
<paramdef>array <parameter>array</parameter></paramdef>
|
||||
<paramdef>bool <parameter><optional>preserve_keys</optional></parameter></paramdef>
|
||||
<paramdef>bool
|
||||
<parameter><optional>preserve_keys</optional></parameter>
|
||||
</paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
|
@ -1070,8 +1073,9 @@ $result_keyed = array_reverse ($input, TRUE);
|
|||
</example>
|
||||
</para>
|
||||
<para>
|
||||
This makes both <varname>$result</varname> and <varname>$result_keyed</varname>
|
||||
be <literal>array(array ("green", "red"), 4.0, "php")</literal>. But
|
||||
This makes both <varname>$result</varname> and
|
||||
<varname>$result_keyed</varname> be <literal>array(array
|
||||
("green", "red"), 4.0, "php")</literal>. But
|
||||
<varname>$result_keyed[0]</varname> is still
|
||||
<literal>"php"</literal>.
|
||||
</para>
|
||||
|
@ -1087,7 +1091,8 @@ $result_keyed = array_reverse ($input, TRUE);
|
|||
<refnamediv>
|
||||
<refname>array_reduce</refname>
|
||||
<refpurpose>
|
||||
Iteratively reduce the array to a single value using a callback function
|
||||
Iteratively reduce the array to a single value using a callback
|
||||
function
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
|
@ -1103,7 +1108,7 @@ $result_keyed = array_reverse ($input, TRUE);
|
|||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
<function>array_reduce</function> applies iteratively the
|
||||
<function>array_reduce</function> applies iteratively the
|
||||
<parameter>callback</parameter> function to the elements of the
|
||||
array <parameter>input</parameter>, so as to reduce the array to
|
||||
a single value. If the optional <parameter>intial</parameter> is
|
||||
|
@ -1115,13 +1120,13 @@ $result_keyed = array_reverse ($input, TRUE);
|
|||
<title><function>array_reduce</function> example</title>
|
||||
<programlisting role="php">
|
||||
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);
|
|||
<para>
|
||||
This will result in <varname>$b</varname> containing
|
||||
<literal>15</literal>, <varname>$c</varname> containing
|
||||
<literal>1200</literal> (= 1*2*3*4*5*10), and <varname>$d</varname>
|
||||
containing <literal>1</literal>.
|
||||
<literal>1200</literal> (= 1*2*3*4*5*10), and
|
||||
<varname>$d</varname> containing <literal>1</literal>.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>array_filter</function>,
|
||||
|
@ -1164,9 +1169,8 @@ $d = array_reduce($x, "rsum", 1);
|
|||
<function>array_shift</function> shifts the first value of the
|
||||
<parameter>array</parameter> off and returns it, shortening the
|
||||
<parameter>array</parameter> by one element and moving everything
|
||||
down.
|
||||
If <parameter>array</parameter> is empty (or is not an array),
|
||||
&null; will be returned.
|
||||
down. If <parameter>array</parameter> is empty (or is not an
|
||||
array), &null; will be returned.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
|
@ -1314,7 +1318,7 @@ $output = array_slice ($input, 0, 3); // returns "a", "b", and "c"
|
|||
</para>
|
||||
<para>
|
||||
The following equivalences hold:
|
||||
<programlisting>
|
||||
<programlisting role="php">
|
||||
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"));
|
|||
<example>
|
||||
<title><function>array_sum</function> examples</title>
|
||||
<programlisting role="php">
|
||||
$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.
|
||||
<example>
|
||||
<title>
|
||||
Implementation of <function>array_values</function> for PHP 3
|
||||
users
|
||||
Implementation of <function>array_values</function> for PHP 3
|
||||
users
|
||||
</title>
|
||||
<programlisting role="php">
|
||||
function array_values ($arr) {
|
||||
|
@ -1735,7 +1739,9 @@ c = apple
|
|||
<funcprototype>
|
||||
<funcdef>void <function>asort</function></funcdef>
|
||||
<paramdef>array <parameter>array</parameter></paramdef>
|
||||
<paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef>
|
||||
<paramdef>int
|
||||
<parameter><optional>sort_flags</optional></parameter>
|
||||
</paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
|
@ -1833,8 +1839,9 @@ $location_vars = array ("city", "state");
|
|||
$result = compact ("event", "nothing_here", $location_vars);
|
||||
</programlisting>
|
||||
<para>
|
||||
After this, <varname>$result</varname> will be <literal>array ("event"
|
||||
=> "SIGGRAPH", "city" => "San Francisco", "state" => "CA")</literal>.
|
||||
After this, <varname>$result</varname> will be <literal>array
|
||||
("event" => "SIGGRAPH", "city" => "San Francisco",
|
||||
"state" => "CA")</literal>.
|
||||
</para>
|
||||
</example>
|
||||
</para>
|
||||
|
@ -1876,9 +1883,9 @@ $result = compact ("event", "nothing_here", $location_vars);
|
|||
</para>
|
||||
</warning>
|
||||
<para>
|
||||
Please see the <link linkend="language.types.array">Arrays</link>
|
||||
section of the manual for a detailed explanation of how arrays are
|
||||
implemented and used in PHP.
|
||||
Please see the <link linkend="language.types.array">Arrays</link>
|
||||
section of the manual for a detailed explanation of how arrays
|
||||
are implemented and used in PHP.
|
||||
</para>
|
||||
<para>
|
||||
<example>
|
||||
|
@ -1960,7 +1967,8 @@ $result = count ($b);
|
|||
<refnamediv>
|
||||
<refname>each</refname>
|
||||
<refpurpose>
|
||||
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
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
|
@ -2115,10 +2123,11 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) {
|
|||
</para>
|
||||
</note>
|
||||
<para>
|
||||
<function>extract</function> 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 <parameter>extract_type</parameter>. It can be one of the
|
||||
<function>extract</function> 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
|
||||
<parameter>extract_type</parameter>. It can be one of the
|
||||
following values:
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
|
@ -2150,8 +2159,9 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) {
|
|||
<term>EXTR_PREFIX_ALL</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
Prefix all variable names with <parameter>prefix</parameter>. Since PHP
|
||||
4.0.5 this includes numeric ones as well.
|
||||
Prefix all variable names with
|
||||
<parameter>prefix</parameter>. Since PHP 4.0.5 this includes
|
||||
numeric ones as well.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -2160,7 +2170,8 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) {
|
|||
<listitem>
|
||||
<simpara>
|
||||
Only prefix invalid/numeric variable names with
|
||||
<parameter>prefix</parameter>. This flag has been added in PHP 4.0.5.
|
||||
<parameter>prefix</parameter>. This flag has been added in
|
||||
PHP 4.0.5.
|
||||
</simpara>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -2172,13 +2183,14 @@ while (list ($key, $val) = each ($HTTP_POST_VARS)) {
|
|||
</para>
|
||||
<para>
|
||||
Note that <parameter>prefix</parameter> is only required if
|
||||
<parameter>extract_type</parameter> 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.
|
||||
<parameter>extract_type</parameter> 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.
|
||||
</para>
|
||||
<para>
|
||||
<function>extract</function> returns the number of variables successfully
|
||||
imported into the symbol table.
|
||||
<function>extract</function> returns the number of variables
|
||||
successfully imported into the symbol table.
|
||||
</para>
|
||||
<para>
|
||||
A possible use for extract is to import into symbol table
|
||||
|
@ -2266,9 +2278,9 @@ blue, large, sphere, medium
|
|||
<title><function>in_array</function> example</title>
|
||||
<programlisting role="php">
|
||||
$os = array ("Mac", "NT", "Irix", "Linux");
|
||||
if (in_array ("Irix", $os)){
|
||||
if (in_array ("Irix", $os)) {
|
||||
print "Got Irix";
|
||||
}
|
||||
}
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
|
@ -2301,7 +2313,8 @@ if (in_array(1.13, $a, TRUE))
|
|||
<refnamediv>
|
||||
<refname>array_search</refname>
|
||||
<refpurpose>
|
||||
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
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
|
@ -2549,8 +2562,8 @@ while (list ($id, $name, $salary) = mysql_fetch_row ($result)) {
|
|||
<example>
|
||||
<title><function>natsort</function> example</title>
|
||||
<programlisting role="php">
|
||||
$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
|
|||
)
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
For more infomation see: Martin Pool's <ulink
|
||||
For more information see: Martin Pool's <ulink
|
||||
url="&url.strnatcmp;">Natural Order String Comparison</ulink>
|
||||
page.
|
||||
</para>
|
||||
|
@ -2765,29 +2778,29 @@ Array
|
|||
<para>
|
||||
<function>range</function> returns an array of elements from
|
||||
<parameter>low</parameter> to <parameter>high</parameter>,
|
||||
inclusive. If low > high, the sequence will be from high to
|
||||
low.
|
||||
inclusive. If low > high, the sequence will be from high to low.
|
||||
<example>
|
||||
<title><function>range</function> examples</title>
|
||||
<programlisting role="php">
|
||||
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;
|
||||
}
|
||||
</programlisting>
|
||||
</example>
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
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.
|
||||
</para>
|
||||
</note>
|
||||
<note>
|
||||
<para>
|
||||
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.
|
||||
</para>
|
||||
</note>
|
||||
<para>
|
||||
See <function>shuffle</function> for another example of its use.
|
||||
</para>
|
||||
|
@ -2935,7 +2948,8 @@ while (list (, $number) = each ($numbers)) {
|
|||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
The <function>sizeof</function> function is an alias for <function>count</function>.
|
||||
The <function>sizeof</function> function is an alias for
|
||||
<function>count</function>.
|
||||
</para>
|
||||
<para>
|
||||
See also <function>count</function>.
|
||||
|
@ -2954,7 +2968,9 @@ while (list (, $number) = each ($numbers)) {
|
|||
<funcprototype>
|
||||
<funcdef>void <function>sort</function></funcdef>
|
||||
<paramdef>array <parameter>array</parameter></paramdef>
|
||||
<paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef>
|
||||
<paramdef>int
|
||||
<parameter><optional>sort_flags</optional></parameter>
|
||||
</paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
|
@ -2962,7 +2978,7 @@ while (list (, $number) = each ($numbers)) {
|
|||
lowest to highest when this function has completed.
|
||||
<example>
|
||||
<title><function>sort</function> example</title>
|
||||
<programlisting role="php">
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
|
||||
$fruits = array ("lemon", "orange", "banana", "apple");
|
||||
|
@ -2994,7 +3010,7 @@ fruits[3] = orange
|
|||
</para>
|
||||
<para>
|
||||
The optional second parameter <parameter>sort_flags</parameter>
|
||||
may be used to modify the sorting behavior using theese valies:
|
||||
may be used to modify the sorting behavior using these values:
|
||||
</para>
|
||||
<para>
|
||||
Sorting type flags:
|
||||
|
@ -3015,7 +3031,8 @@ fruits[3] = orange
|
|||
<function>asort</function>, <function>ksort</function>,
|
||||
<function>natsort</function>, <function>natcasesort</function>,
|
||||
<function>rsort</function>, <function>usort</function>,
|
||||
<function>array_multisort</function>, and <function>uksort</function>.
|
||||
<function>array_multisort</function>, and
|
||||
<function>uksort</function>.
|
||||
</para>
|
||||
<note>
|
||||
<para>
|
||||
|
@ -3203,7 +3220,7 @@ while (list ($key, $value) = each ($a)) {
|
|||
</title>
|
||||
<programlisting role="php">
|
||||
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
|
|||
</warning>
|
||||
</para>
|
||||
<para>
|
||||
See also: <function>uasort</function>, <function>uksort</function>,
|
||||
<function>sort</function>, <function>asort</function>,
|
||||
See also: <function>uasort</function>,
|
||||
<function>uksort</function>, <function>sort</function>,
|
||||
<function>asort</function>,
|
||||
<function>arsort</function>,<function>ksort</function>,
|
||||
<function>natsort</function>, and <function>rsort</function>.
|
||||
</para>
|
||||
|
|
Loading…
Reference in a new issue