cvs: phpdoc /kr/functions array.xml
| From: | cycle98 | Date: | Fri, 02 Mar 2001 08:41:54 +0000 |
| Subject: | cvs: phpdoc /kr/functions array.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969334546@lists.php.net to get a copy of this message | ||
cycle98 Fri Mar 2 00:41:54 2001 EDT
Modified files:
/phpdoc/kr/functions array.xml
Log:
50% TRANSLATION
Index: phpdoc/kr/functions/array.xml diff -u phpdoc/kr/functions/array.xml:1.3 phpdoc/kr/functions/array.xml:1.4 --- phpdoc/kr/functions/array.xml:1.3 Wed Feb 28 04:07:42 2001 +++ phpdoc/kr/functions/array.xml Fri Mar 2 00:41:53 2001 @@ -1,2780 +1,2795 @@ - <reference id="ref.array"> - <title>Array Functions</title> - <titleabbrev>Arrays</titleabbrev> - <partintro> - <simpara> - These functions allow you to interact with and manipulate - arrays in various ways. Arrays are essential for storing, - managing, and operating on sets of variables. - </simpara> - <simpara> - Simple and multi-dimensional arrays are supported, and may be - either user created or created by another function. - There are specific database handling functions for populating - arrays from database queries, and several functions return arrays. - </simpara> - <para> - See also <function>is_array</function>, <function>explode</function>, - <function>implode</function>, <function>split</function> - and <function>join</function>. - </para> - </partintro> - - <refentry id="function.array"> - <refnamediv> - <refname>array</refname> - <refpurpose> - Create an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array</function></funcdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns an array of the parameters. The parameters can be given - an index with the <literal>=></literal> operator. - </para> - <para> - <note> - <para> - <function>Array</function> is a language construct used to - represent literal arrays, and not a regular function. - </para> - </note> - </para> - <para> - 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. - </para> - <para> - 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 - arrays. - <example> - <title><function>Array</function> example</title> - <programlisting role="php"> -$fruits = array ( - "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"), - "numbers" => array (1, 2, 3, 4, 5, 6), - "holes" => array ("first", 5 => "second", "third") -); - </programlisting> - </example> - </para> - <para> - <example> - <title>Automatic index with <function>Array</function></title> - <programlisting role="php"> -$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); -print_r($array); - </programlisting> - </example> - which will display : - <informalexample> - <programlisting> -Array -( - [0] => 1 - [1] => 1 - [2] => 1 - [3] => 13 - [4] => 1 - [8] => 1 - [9] => 19 -) - </programlisting> - </informalexample> - 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. - </para> - <para> - This example creates a 1-based array. - <example> - <title>1-based index with <function>Array</function></title> - <programlisting role="php"> - $firstquarter = array(1 => 'January', 'February', 'March'); - print_r($firstquarter); - </programlisting> - </example> - which will display : - <informalexample> - <programlisting> -Array -( - [1] => 'January' - [2] => 'February' - [3] => 'March' -) - </programlisting> - </informalexample> - </para> - <para> - See also: <function>list</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-count-values"> - <refnamediv> - <refname>array_count_values</refname> - <refpurpose>Counts all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_count_values</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_count_values</function> returns an array using - the values of the <parameter>input</parameter> array as keys and - their frequency in <parameter>input</parameter> as values. - </para> - <para> - <example> - <title><function>Array_count_values</function> example</title> - <programlisting role="php"> -$array = array (1, "hello", 1, "world", "hello"); -array_count_values ($array); // returns array (1=>2, "hello"=>2, "world"=>1) - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-diff"> - <refnamediv> - <refname>array_diff</refname> - <refpurpose>Computes the difference of arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_diff</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional> ...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_diff</function> returns an array - containing all the values of <parameter>array1</parameter> - that are not present in any of the other arguments. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_diff</function> example</title> - <programlisting role="php"> -$array1 = array ("a" => "green", "red", "blue"); -$array2 = array ("b" => "green", "yellow", "red"); -$result = array_diff ($array1, $array2); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array - ("blue");</literal> - </para> - <para> - See also <function>array_intersect</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-flip"> - <refnamediv> - <refname>array_flip</refname> - <refpurpose>Flip all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_flip</function></funcdef> - <paramdef>array <parameter>trans</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_flip</function> returns an array in flip order. - </para> - <para> - <example> - <title><function>Array_flip</function> example</title> - <programlisting role="php"> -$trans = array_flip ($trans); -$original = strtr ($str, $trans); - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-intersect"> - <refnamediv> - <refname>array_intersect</refname> - <refpurpose>Computes the intersection of arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_intersect</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional> ...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_intersect</function> returns an array - containing all the values of <parameter>array1</parameter> - that are present in all the arguments. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_intersect</function> example</title> - <programlisting role="php"> -$array1 = array ("a" => "green", "red", "blue"); -$array2 = array ("b" => "green", "yellow", "red"); -$result = array_intersect ($array1, $array2); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array ("a" - => "green", "red");</literal> - </para> - <para> - See also <function>array_diff</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-keys"> - <refnamediv> - <refname>array_keys</refname> - <refpurpose>Return all the keys of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_keys</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>mixed - <parameter> - <optional>search_value</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_keys</function> returns the keys, numeric and - string, from the <parameter>input</parameter> array. - </para> - <para> - If the optional <parameter>search_value</parameter> is specified, - then only the keys for that value are returned. Otherwise, all - the keys from the <parameter>input</parameter> are returned. - </para> - <para> - <example> - <title><function>Array_keys</function> example</title> - <programlisting role="php"> -$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") - </programlisting> - </example> - </para> - <note> - <para> - This function was added to PHP 4, below is an implementation for - those still using PHP 3. - <example> - <title> - 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) - continue; - $t[] = $k; - } - return $t; -} - </programlisting> - </example> - </para> - </note> - <para> - See also <function>array_values</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-merge"> - <refnamediv> - <refname>array_merge</refname> - <refpurpose>Merge two or more arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_merge</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_merge</function> merges the elements of two or - more arrays together so that the values of one are appended to - the end of the previous one. It returns the resulting array. - </para> - <para> - If the input arrays have the same string keys, then the later - value for that key will overwrite the previous one. If, however, - the arrays have the same numeric key, the later value will not - overwrite the original value, but will be appended. - </para> - <para> - <example> - <title><function>array_merge</function> example</title> - <programlisting role="php"> -$array1 = array ("color" => "red", 2, 4); -$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4); -array_merge ($array1, $array2); - </programlisting> - </example> - </para> - <para> - Resulting array will be <literal>array("color" => "green", 2, 4, - "a", "b", "shape" => "trapezoid", 4)</literal>. - </para> - <para> - See also <function>array_merge_recursive</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-merge-recursive"> - <refnamediv> - <refname>array_merge_recursive</refname> - <refpurpose>Merge two or more arrays recursively</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_merge_recursive</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_merge_recursive</function> merges the elements of - two or more arrays together so that the values of one are appended - to the end of the previous one. It returns the resulting array. - </para> - <para> - If the input arrays have the same string keys, then the values for - these keys are merged together into an array, and this is done - recursively, so that if one of the values is an array itself, the - function will merge it with a corresponding entry in another array - too. If, however, the arrays have the same numeric key, the later - value will not overwrite the original value, but will be appended. - </para> - <para> - <example> - <title><function>Array_merge_recursive</function> example</title> - <programlisting role="php"> -$ar1 = array ("color" => array ("favorite" => "red"), 5); -$ar2 = array (10, "color" => array ("favorite" => "green", "blue")); -$result = array_merge_recursive ($ar1, $ar2); - </programlisting> - </example> - </para> - <para> - Resulting array will be <literal>array ("color" => array - ("favorite" => array ("red", "green"), "blue"), 5, 10)</literal>. - </para> - <para> - See also <function>array_merge</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-multisort"> - <refnamediv> - <refname>array_multisort</refname> - <refpurpose>Sort multiple or multi-dimensional arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>bool <function>array_multisort</function></funcdef> - <paramdef>array <parameter>ar1</parameter></paramdef> - <paramdef>mixed - <parameter><optional>arg</optional></parameter> - </paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_multisort</function> can be used to sort several - arrays at once or a multi-dimensional array according by one of - more dimensions. It maintains key association when sorting. - </para> - <para> - The input arrays are treated as columns of a table to be sorted - by rows - this resembles the functionality of SQL ORDER BY - clause. The first array is the primary one to sort by. The rows - (values) in that array that compare the same are sorted by the - next input array, and so on. - </para> - <para> - The argument structure of this function is a bit unusual, but - flexible. The very first argument has to be an - array. Subsequently, each argument can be either an array or a - sorting flag from the following lists. - </para> - <para> - Sorting order flags: - <itemizedlist> - <listitem> - <simpara>SORT_ASC - sort in ascending order</simpara> - </listitem> - <listitem> - <simpara>SORT_DESC - sort in descending order</simpara> - </listitem> - </itemizedlist> - </para> - <para> - Sorting type flags: - <itemizedlist> - <listitem> - <simpara>SORT_REGULAR - compare items normally</simpara> - </listitem> - <listitem> - <simpara>SORT_NUMERIC - compare items numerically</simpara> - </listitem> - <listitem> - <simpara>SORT_STRING - compare items as strings</simpara> - </listitem> - </itemizedlist> - </para> - <para> - No two sorting flags of the same type can be specified after each - array. The sortings flags specified after an array argument apply - only to that array - they are reset to default SORT_ASC and - SORT_REGULAR after before each new array argument. - </para> - <para> - Returns <literal>TRUE</literal> on success, <literal>FALSE</literal> - on failure. - </para> - <para> - <example> - <title>Sorting multiple arrays</title> - <programlisting role="php"> -$ar1 = array ("10", 100, 100, "a"); -$ar2 = array (1, 3, "2", 1); -array_multisort ($ar1, $ar2); - </programlisting> - </example> - </para> - <para> - In this example, after sorting, the first array will contain 10, - "a", 100, 100. The second array will contain 1, 1, 2, "3". The - entries in the second array corresponding to the identical - entries in the first array (100 and 100) were sorted as well. - </para> - <para> - <example> - <title>Sorting multi-dimensional array</title> - <programlisting role="php"> -$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); -array_multisort ($ar[0], SORT_ASC, SORT_STRING, - $ar[1], SORT_NUMERIC, SORT_DESC); - </programlisting> - </example> - </para> - <para> - In this example, after sorting, the first array will contain 10, - 100, 100, "a" (it was sorted as strings in ascending order), and - the second one will contain 1, 3, "2", 1 (sorted as numbers, in - descending order). - </para> - </refsect1> - </refentry> - - <refentry id="function.array-pad"> - <refnamediv> - <refname>array_pad</refname> - <refpurpose> - Pad array to the specified length with a value - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_pad</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int <parameter>pad_size</parameter></paramdef> - <paramdef>mixed <parameter>pad_value</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_pad</function> returns a copy of the - <parameter>input</parameter> padded to size specified by - <parameter>pad_size</parameter> with value - <parameter>pad_value</parameter>. If - <parameter>pad_size</parameter> is positive then the array is - padded on the right, if it's negative then on the left. If the - absolute value of <parameter>pad_size</parameter> is less than or - equal to the length of the <parameter>input</parameter> then no - padding takes place. - </para> - <para> - <example> - <title><function>Array_pad</function> example</title> - <programlisting role="php"> -$input = array (12, 10, 9); - -$result = array_pad ($input, 5, 0); -// result is array (12, 10, 9, 0, 0) - -$result = array_pad ($input, -7, -1); -// result is array (-1, -1, -1, -1, 12, 10, 9) - -$result = array_pad ($input, 2, "noop"); -// not padded - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-pop"> - <refnamediv> - <refname>array_pop</refname> - <refpurpose>Pop the element off the end of array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_pop</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_pop</function> pops and returns the last value of - the <parameter>array</parameter>, shortening the - <parameter>array</parameter> by one element. - </para> - <para> - <example> - <title><function>Array_pop</function> example</title> - <programlisting role="php"> -$stack = array ("orange", "apple", "raspberry"); -$fruit = array_pop ($stack); - </programlisting> - </example> - </para> - <para> - After this, <varname>$stack</varname> has only 2 elements: - "orange" and "apple", and <varname>$fruit</varname> has - "raspberry". - </para> - <para> - See also <function>array_push</function>, - <function>array_shift</function>, and - <function>array_unshift</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-push"> - <refnamediv> - <refname>array_push</refname> - <refpurpose> - Push one or more elements onto the end of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_push</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_push</function> treats - <parameter>array</parameter> as a stack, and pushes the passed - variables onto the end of <parameter>array</parameter>. The - length of <parameter>array</parameter> increases by the number of - variables pushed. Has the same effect as: - <programlisting role="php"> -$array[] = $var; - </programlisting> - repeated for each <parameter>var</parameter>. - </para> - <para> - Returns the new number of elements in the array. - </para> - <para> - <example> - <title><function>Array_push</function> example</title> - <programlisting role="php"> -$stack = array (1, 2); -array_push ($stack, "+", 3); - </programlisting> - </example> - </para> - <para> - This example would result in <varname>$stack</varname> having 4 - elements: 1, 2, "+", and 3. - </para> - <para> - See also: <function>array_pop</function>, - <function>array_shift</function>, and - <function>array_unshift</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-rand"> - <refnamediv> - <refname>array_rand</refname> - <refpurpose> - Pick one or more random entries out of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_rand</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int - <parameter><optional>num_req</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_rand</function> is rather useful when you want to - pick one or more random entries out of an array. It takes an - <parameter>input</parameter> array and an optional argument - <parameter>num_req</parameter> which specifies how many entries you - want to pick - if not specified, it defaults to 1. - </para> - <para> - If you are picking only one entry, <function>array_rand</function> - returns the key for a random entry. Otherwise, it returns an array - of keys for the random entries. This is done so that you can pick - random keys as well as values out of the array. - </para> - <para> - Don't forget to call <function>srand</function> to seed the random - number generator. - </para> - <para> - <example> - <title><function>Array_rand</function> example</title> - <programlisting role="php"> -srand ((double) microtime() * 10000000); -$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); -$rand_keys = array_rand ($input, 2); -print $input[$rand_keys[0]]."\n"; -print $input[$rand_keys[1]]."\n"; - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-reverse"> - <refnamediv> - <refname>array_reverse</refname> - <refpurpose> - Return an array with elements in reverse order - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_reverse</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>bool <parameter><optional>preserve_keys</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_reverse</function> takes input - <parameter>array</parameter> and returns a new array with the - order of the elements reversed, preserving the keys if - <parameter>preserve_keys</parameter> is <literal>TRUE</literal>. - </para> - <para> - <example> - <title><function>Array_reverse</function> example</title> - <programlisting role="php"> -$input = array ("php", 4.0, array ("green", "red")); -$result = array_reverse ($input); -$result_keyed = array_reverse ($input, TRUE); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array - (array ("green", "red"), 4.0, "php")</literal>. But - <varname>$result2[0]</varname> is still - <literal>"php"</literal>. - </para> - <note> - <para> - The second parameter was added in PHP 4.0.3. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.array-shift"> - <refnamediv> - <refname>array_shift</refname> - <refpurpose> - Pop an element off the beginning of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_shift</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <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. - </para> - <para> - <example> - <title><function>Array_shift</function> example</title> - <programlisting role="php"> -$args = array ("-v", "-f"); -$opt = array_shift ($args); - </programlisting> - </example> - </para> - <para> - This would result in <varname>$args</varname> having one element - "-f" left, and <varname>$opt</varname> being "-v". - </para> - <para> - See also <function>array_unshift</function>, - <function>array_push</function>, and - <function>array_pop</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-slice"> - <refnamediv> - <refname>array_slice</refname> - <refpurpose>Extract a slice of the array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_slice</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter>offset</parameter></paramdef> - <paramdef>int - <parameter> - <optional>length</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_slice</function> returns a sequence of elements - from the <parameter>array</parameter> specified by the - <parameter>offset</parameter> and <parameter>length</parameter> - parameters. - </para> - <para> - If <parameter>offset</parameter> is positive, the sequence will - start at that offset in the <parameter>array</parameter>. If - <parameter>offset</parameter> is negative, the sequence will - start that far from the end of the <parameter>array</parameter>. - </para> - <para> - If <parameter>length</parameter> is given and is positive, then - the sequence will have that many elements in it. If - <parameter>length</parameter> is given and is negative then the - sequence will stop that many elements from the end of the - array. If it is omitted, then the sequence will have everything - from <parameter>offset</parameter> up until the end of the - <parameter>array</parameter>. - </para> - <para> - <example> - <title><function>Array_slice</function> examples</title> - <programlisting role="php"> -$input = array ("a", "b", "c", "d", "e"); - -$output = array_slice ($input, 2); // returns "c", "d", and "e" -$output = array_slice ($input, 2, -1); // returns "c", "d" -$output = array_slice ($input, -2, 1); // returns "d" -$output = array_slice ($input, 0, 3); // returns "a", "b", and "c" - </programlisting> - </example> - </para> - <para> - See also <function>array_splice</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-splice"> - <refnamediv> - <refname>array_splice</refname> - <refpurpose> - Remove a portion of the array and replace it with something - else - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_splice</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int <parameter>offset</parameter></paramdef> - <paramdef>int - <parameter><optional>length</optional></parameter> - </paramdef> - <paramdef>array - <parameter> - <optional>replacement</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_splice</function> removes the elements designated - by <parameter>offset</parameter> and - <parameter>length</parameter> from the - <parameter>input</parameter> array, and replaces them with the - elements of the <parameter>replacement</parameter> array, if - supplied. - </para> - <para> - If <parameter>offset</parameter> is positive then the start of - removed portion is at that offset from the beginning of the - <parameter>input</parameter> array. If - <parameter>offset</parameter> is negative then it starts that far - from the end of the <parameter>input</parameter> array. - </para> - <para> - If <parameter>length</parameter> is omitted, removes everything - from <parameter>offset</parameter> to the end of the array. If - <parameter>length</parameter> is specified and is positive, then - that many elements will be removed. If - <parameter>length</parameter> is specified and is negative then - the end of the removed portion will be that many elements from - the end of the array. Tip: to remove everything from - <parameter>offset</parameter> to the end of the array when - <parameter>replacement</parameter> is also specified, use - <literal>count($input)</literal> for - <parameter>length</parameter>. - </para> - <para> - If <parameter>replacement</parameter> array is specified, then - the removed elements are replaced with elements from this array. - If <parameter>offset</parameter> and - <parameter>length</parameter> are such that nothing is removed, - then the elements from the <parameter>replacement</parameter> - array are inserted in the place specified by the - <parameter>offset</parameter>. Tip: if the replacement is just - one element it is not necessary to put <literal>array()</literal> - around it, unless the element is an array itself. - </para> - <para> - The following equivalences hold: - <programlisting> -array_push ($input, $x, $y) array_splice ($input, count ($input), 0, - array ($x, $y)) -array_pop ($input) array_splice ($input, -1) -array_shift ($input) array_splice ($input, 0, 1) -array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y)) -$a[$x] = $y array_splice ($input, $x, 1, $y) - </programlisting> - </para> - <para> - Returns the array consisting of removed elements. - </para> - <para> - <example> - <title><function>Array_splice</function> examples</title> - <programlisting role="php"> -$input = array ("red", "green", "blue", "yellow"); - -array_splice ($input, 2); // $input is now array ("red", "green") -array_splice ($input, 1, -1); // $input is now array ("red", "yellow") -array_splice ($input, 1, count($input), "orange"); - // $input is now array ("red", "orange") -array_splice ($input, -1, 1, array("black", "maroon")); - // $input is now array ("red", "green", - // "blue", "black", "maroon") - </programlisting> - </example> - </para> - <para> - See also <function>array_slice</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-unique"> - <refnamediv> - <refname>array_unique</refname> - <refpurpose>Removes duplicate values from an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_unique</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_unique</function> takes input - <parameter>array</parameter> and returns a new array - without duplicate values. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_unique</function> example</title> - <programlisting role="php"> -$input = array ("a" => "green", "red", "b" => "green", "blue", "red"); -$result = array_unique ($input); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array ("a" => - "green", "red", "blue");</literal>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-unshift"> - <refnamediv> - <refname>array_unshift</refname> - <refpurpose> - Push one or more elements onto the beginning of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_unshift</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - <paramdef>mixed - <parameter> - <optional>...</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_unshift</function> prepends passed elements to - the front of the <parameter>array</parameter>. Note that the list - of elements is prepended as a whole, so that the prepended - elements stay in the same order. - </para> - <para> - Returns the new number of elements in the - <parameter>array</parameter>. - </para> - <para> - <example> - <title><function>Array_unshift</function> example</title> - <programlisting role="php"> -$queue = array ("p1", "p3"); -array_unshift ($queue, "p4", "p5", "p6"); - </programlisting> - </example> - </para> - <para> - This would result in <varname>$queue</varname> having 5 - elements: "p4", "p5", "p6", "p1", and "p3". - </para> - <para> - See also <function>array_shift</function>, - <function>array_push</function>, and - <function>array_pop</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-values"> - <refnamediv> - <refname>array_values</refname> - <refpurpose>Return all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_values</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>array_values</function> returns all the values from the - <parameter>input</parameter> array. - </para> - <para> - <example> - <title><function>Array_values</function> example</title> - <programlisting role="php"> -$array = array ("size" => "XL", "color" => "gold"); -array_values ($array); // returns array ("XL", "gold") - </programlisting> - </example> - </para> - <note> - <para> - This function was added to PHP 4, below is an implementation for - those still using PHP 3. - <example> - <title> - Implementation of <function>array_values</function> for PHP 3 - users - </title> - <programlisting role="php"> -function array_values ($arr) { - $t = array(); - while (list($k, $v) = each ($arr)) { - $t[] = $v; - return $t; - } -} - </programlisting> - </example> - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.array-walk"> - <refnamediv> - <refname>array_walk</refname> - <refpurpose> - Apply a user function to every member of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_walk</function></funcdef> - <paramdef>array <parameter>arr</parameter></paramdef> - <paramdef>string <parameter>func</parameter></paramdef> - <paramdef>mixed <parameter>userdata</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <simpara> - Applies the function named by <parameter>func</parameter> to each - element of <parameter>arr</parameter>. - <parameter>func</parameter> will be passed array value as the - first parameter and array key as the second parameter. If - <parameter>userdata</parameter> is supplied, it will be passed as - the third parameter to the user function. - </simpara> - <simpara> - If <parameter>func</parameter> requires more than two or three - arguments, depending on <parameter>userdata</parameter>, a - warning will be generated each time - <function>array_walk</function> calls - <parameter>func</parameter>. These warnings may be suppressed by - prepending the '@' sign to the <function>array_walk</function> - call, or by using <function>error_reporting</function>. - </simpara> - <note> - <para> - If <parameter>func</parameter> needs to be working with the - actual values of the array, specify that the first parameter of - <parameter>func</parameter> should be passed by reference. Then - any changes made to those elements will be made in the array - itself. - </para> - </note> - <note> - <para> - Passing the key and userdata to <parameter>func</parameter> was - added in 4.0. - </para> - <para> - In PHP 4 <function>reset</function> needs to be called as - necessary since <function>array_walk</function> does not reset - the array by default. - </para> - </note> - <para> - <example> - <title><function>Array_walk</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); - -function test_alter (&$item1, $key, $prefix) { - $item1 = "$prefix: $item1"; -} - -function test_print ($item2, $key) { - echo "$key. $item2<br>\n"; -} - -array_walk ($fruits, 'test_print'); -reset ($fruits); -array_walk ($fruits, 'test_alter', 'fruit'); -reset ($fruits); -array_walk ($fruits, 'test_print'); - </programlisting> - </example> - </para> - <simpara> - See also <function>each</function> and <function>list</function>. - </simpara> - </refsect1> - </refentry> - - <refentry id="function.arsort"> - <refnamediv> - <refname>arsort</refname> - <refpurpose> - Sort an array in reverse order and maintain index association - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>arsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. - <example> - <title><function>Arsort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -arsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key = $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[a] = orange -fruits[d] = lemon -fruits[b] = banana -fruits[c] = apple - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in reverse alphabetical order, and - the index associated with each element has been maintained. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also: <function>asort</function>, <function>rsort</function>, - <function>ksort</function>, and <function>sort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.asort"> - <refnamediv> - <refname>asort</refname> - <refpurpose>Sort an array and maintain index association</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>asort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. - <example> - <title><function>Asort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -asort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key = $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[c] = apple -fruits[b] = banana -fruits[d] = lemon -fruits[a] = orange - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in alphabetical order, and the index - associated with each element has been maintained. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also <function>arsort</function>, <function>rsort</function>, - <function>ksort</function>, and <function>sort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.compact"> - <refnamediv> - <refname>compact</refname> - <refpurpose> - Create array containing variables and their values - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>compact</function></funcdef> - <paramdef>mixed <parameter>varname</parameter></paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Compact</function> takes a variable number of - parameters. Each parameter can be either a string containing the - name of the variable, or an array of variable names. The array - can contain other arrays of variable names inside it; - <function>compact</function> handles it recursively. - </para> - <para> - For each of these, <function>compact</function> looks for a - variable with that name in the current symbol table and adds it - to the output array such that the variable name becomes the key - and the contents of the variable become the value for that key. - In short, it does the opposite of <function>extract</function>. - It returns the output array with all the variables added to it. - </para> - <para> - Any strings that are not set will simply be skipped. - </para> - <para> - <example> - <title><function>Compact</function> example</title> - <programlisting role="php"> -$city = "San Francisco"; -$state = "CA"; -$event = "SIGGRAPH"; - -$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>. - </para> - </example> - </para> - <para> - See also <function>extract</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.count"> - <refnamediv> - <refname>count</refname> - <refpurpose>Count elements in a variable</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>count</function></funcdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the number of elements in <parameter>var</parameter>, - which is typically an array (since anything else will have one - element). - </para> - <para> - Returns 1 if the variable is not an array. - </para> - <para> - Returns 0 if the variable is not set. - <warning> - <para> - <function>Count</function> may return 0 for a variable that - isn't set, but it may also return 0 for a variable that has - been initialized with an empty array. Use - <function>isset</function> to test if a variable is set. - </para> - </warning> - </para> - <para> - <example> - <title><function>Count</function> example</title> - <programlisting role="php"> -$a[0] = 1; -$a[1] = 3; -$a[2] = 5; -$result = count ($a); -//$result == 3 - </programlisting> - </example> - </para> - <para> - See also: <function>sizeof</function>, - <function>isset</function>, and - <function>is_array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.current"> - <refnamediv> - <refname>current</refname> - <refpurpose>Return the current element in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>current</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Every array has an internal pointer to its "current" element, - which is initialized to the first element inserted into the - array. - </para> - <para> - The <function>current</function> function simply returns the - 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, - <function>current</function> returns <literal>FALSE</literal>. - <warning> - <para> - If the array contains empty elements (0 or "", the empty - string) then this function will return <literal>FALSE</literal> - 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 <function>current</function>. To properly - traverse an array that may contain empty elements, use the - <function>each</function> function. - </para> - </warning> - </para> - <para> - See also: <function>end</function>, <function>next</function>, - <function>prev</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.each"> - <refnamediv> - <refname>each</refname> - <refpurpose> - Return the next key and value pair from an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>each</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the current key and value pair from the array - <parameter>array</parameter> and advances the array cursor. This - pair is returned in a four-element array, with the keys - <emphasis>0</emphasis>, <emphasis>1</emphasis>, - <emphasis>key</emphasis>, and - <emphasis>value</emphasis>. Elements <emphasis>0</emphasis> and - <emphasis>key</emphasis> contain the key name of the array - element, and <emphasis>1</emphasis> and - <emphasis>value</emphasis> contain the data. - </para> - <para> - If the internal pointer for the array points past the end of the - array contents, <function>each</function> returns - <literal>FALSE</literal>. - </para> - <para> - <example> - <title><function>Each</function> examples</title> - <programlisting role="php"> -$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese"); -$bar = each ($foo); - </programlisting> - <para> - <varname>$bar</varname> now contains the following key/value - pairs: - <itemizedlist spacing="compact"> - <listitem><simpara>0 => 0</simpara></listitem> - <listitem><simpara>1 => 'bob'</simpara></listitem> - <listitem><simpara>key => 0</simpara></listitem> - <listitem><simpara>value => 'bob'</simpara></listitem> - </itemizedlist> - <programlisting role="php"> -$foo = array ("Robert" => "Bob", "Seppo" => "Sepi"); -$bar = each ($foo); - </programlisting> - </para> - <para> - <varname>$bar</varname> now contains the following key/value - pairs: - <itemizedlist spacing="compact"> - <listitem><simpara>0 => 'Robert'</simpara></listitem> - <listitem><simpara>1 => 'Bob'</simpara></listitem> - <listitem><simpara>key => 'Robert'</simpara></listitem> - <listitem><simpara>value => 'Bob'</simpara></listitem> - </itemizedlist> - </para> - </example> - </para> - <para> - <function>Each</function> is typically used in conjunction with - <function>list</function> to traverse an array; for instance, - <varname>$HTTP_POST_VARS</varname>: - <example> - <title> - Traversing <varname>$HTTP_POST_VARS</varname> with - <function>each</function> - </title> - <programlisting role="php"> -echo "Values submitted via POST method:<br>"; -reset ($HTTP_POST_VARS); -while (list ($key, $val) = each ($HTTP_POST_VARS)) { - echo "$key => $val<br>"; -} - </programlisting> - </example> - </para> - <para> - After <function>each</function> has executed, the array cursor - will be left on the next element of the array, or on the last - element if it hits the end of the array. - </para> - <para> - See also <function>key</function>, <function>list</function>, - <function>current</function>, <function>reset</function>, - <function>next</function>, and <function>prev</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.end"> - <refnamediv> - <refname>end</refname> - <refpurpose> - Set the internal pointer of an array to its last element - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>end</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>End</function> advances <parameter>array</parameter>'s - internal pointer to the last element, and returns that element. - </para> - <para> - See also: <function>current</function>, - <function>each</function>, <function>end</function>, - <function>next</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.extract"> - <refnamediv> - <refname>extract</refname> - <refpurpose> - Import variables into the symbol table from an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>extract</function></funcdef> - <paramdef>array <parameter>var_array</parameter></paramdef> - <paramdef>int - <parameter><optional>extract_type</optional></parameter> - </paramdef> - <paramdef>string - <parameter><optional>prefix</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function is used to import variables from an array into the - current symbol table. It takes associative array - <parameter>var_array</parameter> and treats keys as variable - names and values as variable values. For each key/value pair it - will create a variable in the current symbol table, subject to - <parameter>extract_type</parameter> and - <parameter>prefix</parameter> parameters. - </para> - <note> - <para> - Since version 4.0.5 this function returns the number of - variables extracted. - </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 - following values: - <variablelist> - <varlistentry> - <term>EXTR_OVERWRITE</term> - <listitem> - <simpara> - If there is a collision, overwrite the existing variable. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_SKIP</term> - <listitem> - <simpara> - If there is a collision, don't overwrite the existing - variable. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_PREFIX_SAME</term> - <listitem> - <simpara>If there is a collision, prefix the variable name with - <parameter>prefix</parameter>. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <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. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_PREFIX_INVALID</term> - <listitem> - <simpara> - Only prefix invalid/numeric variable names with - <parameter>prefix</parameter>. This flag has been added in PHP 4.0.5. - </simpara> - </listitem> - </varlistentry> - </variablelist> - </para> - <para> - If <parameter>extract_type</parameter> is not specified, it is - assumed to be EXTR_OVERWRITE. - </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. - </para> - <para> - <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 - variables contained in an associative array returned by - <function>wddx_deserialize</function>. - </para> - <para> - <example> - <title><function>Extract</function> example</title> - <programlisting role="php"> -<?php - -/* Suppose that $var_array is an array returned from - wddx_deserialize */ - -$size = "large"; -$var_array = array ("color" => "blue", - "size" => "medium", - "shape" => "sphere"); -extract ($var_array, EXTR_PREFIX_SAME, "wddx"); - -print "$color, $size, $shape, $wddx_size\n"; - -?> - </programlisting> - </example> - </para> - <para> - The above example will produce: - <programlisting> -blue, large, sphere, medium - </programlisting> - </para> - <para> - The <varname>$size</varname> wasn't overwritten, becaus we - specified EXTR_PREFIX_SAME, which resulted in - <varname>$wddx_size</varname> being created. If EXTR_SKIP was - specified, then $wddx_size wouldn't even have been created. - EXTR_OVERWRITE would have cause <varname>$size</varname> to have - value "medium", and EXTR_PREFIX_ALL would result in new variables - being named <varname>$wddx_color</varname>, - <varname>$wddx_size</varname>, and - <varname>$wddx_shape</varname>. - </para> - <para> - You must use an associative array, a numerically indexed array - will not produce results. - </para> - <para> - See also: <function>compact</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.in-array"> - <refnamediv> - <refname>in_array</refname> - <refpurpose>Return TRUE if a value exists in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>bool in_array</funcdef> - <paramdef>mixed <parameter>needle</parameter></paramdef> - <paramdef>array <parameter>haystack</parameter></paramdef> - <paramdef>bool <parameter>strict</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Searches <parameter>haystack</parameter> for - <parameter>needle</parameter> and returns <literal>TRUE</literal> - if it is found in the array, <literal>FALSE</literal> otherwise. - </para> - <para> - If the third parameter <parameter>strict</parameter> is set to - <literal>TRUE</literal> then the <function>in_array</function> - will also check the types of the <parameter>needle</parameter> - in the <parameter>haystack</parameter>. - </para> - <para> - <example> - <title><function>In_array</function> example</title> - <programlisting role="php"> -$os = array ("Mac", "NT", "Irix", "Linux"); -if (in_array ("Irix", $os)){ - print "Got Irix"; - } - </programlisting> - </example> - </para> - <para> - <example> - <title><function>In_array</function> with strict example</title> - <programlisting role="php"> -<?php -$a = array('1.10', 12.4, 1.13); - -if (in_array('12.4', $a, TRUE)) - echo "'12.4' found with strict check\n"; -if (in_array(1.13, $a, TRUE)) - echo "1.13 found with strict check\n"; -?> - -// This will output: - -1.13 found with strict check - </programlisting> - </example> - </para> - <para> - See also <function>array_search</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-search"> - <refnamediv> - <refname>array_search</refname> - <refpurpose> - Searches the array for a given value and returns the corresponding key if successful - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_search</function></funcdef> - <paramdef>mixed <parameter>needle</parameter></paramdef> - <paramdef>array <parameter>haystack</parameter></paramdef> - <paramdef>bool <parameter>strict</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Searches <parameter>haystack</parameter> for - <parameter>needle</parameter> and returns the key if it is found in - the array, <literal>FALSE</literal> otherwise. - </para> - <para> - If the third parameter <parameter>strict</parameter> is set to - <literal>TRUE</literal> then the <function>array_search</function> - will also check the types of the <parameter>needle</parameter> - in the <parameter>haystack</parameter>. - </para> - <para> - See also <function>in_array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.key"> - <refnamediv> - <refname>key</refname> - <refpurpose>Fetch a key from an associative array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>key</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Key</function> returns the index element of the - current array position. - </para> - <para> - See also <function>current</function> and <function>next</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.krsort"> - <refnamediv> - <refname>krsort</refname> - <refpurpose>Sort an array by key in reverse order</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>krsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Sorts an array by key in reverse order, maintaining key to data - correlations. This is useful mainly for associative arrays. - <example> - <title><function>Krsort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -krsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[d] = lemon -fruits[c] = apple -fruits[b] = banana -fruits[a] = orange - </programlisting> - </informalexample> - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <simpara> - See also <function>asort</function>, <function>arsort</function>, - <function>ksort</function> <function>sort</function>, - <function>natsort</function>and <function>rsort</function>. - </simpara> - </refsect1> - </refentry> - - <refentry id="function.ksort"> - <refnamediv> - <refname>ksort</refname> - <refpurpose>Sort an array by key</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>ksort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Sorts an array by key, maintaining key to data correlations. This - is useful mainly for associative arrays. - <example> - <title><function>Ksort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -ksort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[a] = orange -fruits[b] = banana -fruits[c] = apple -fruits[d] = lemon - </programlisting> - </informalexample> - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <simpara> - See also <function>asort</function>, <function>arsort</function>, - <function>sort</function>, <function>natsort</function>, and - <function>rsort</function>. - </simpara> - <note> - <para> - The second parameter was added in PHP 4. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.list"> - <refnamediv> - <refname>list</refname> - <refpurpose> - Assign variables as if they were an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>list</function></funcdef> - <varargs/> - </funcprototype> - </funcsynopsis> - <para> - Like <function>array</function>, this is not really a function, - but a language construct. <function>list</function> is used to - assign a list of variables in one operation. - <example> - <title><function>List</function> example</title> - <programlisting role="php"> -<table> - <tr> - <th>Employee name</th> - <th>Salary</th> - </tr> - -<?php - -$result = mysql ($conn, "SELECT id, name, salary FROM employees"); -while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { - print (" <tr>\n". - " <td><a href=\"info.php3?id=$id\">$name</a></td>\n". - " <td>$salary</td>\n". - " </tr>\n"); -} - -?> - -</table> - </programlisting> - </example> - </para> - <para> - See also <function>each</function> and <function>array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.natsort"> - <refnamediv> - <refname>natsort</refname> - <refpurpose> - Sort an array using a "natural order" algorithm - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>natsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function implements a sort algorithm that orders - alphanumeric strings in the way a human being would. This is - described as a "natural ordering". An example of the difference - between this algorithm and the regular computer string sorting - algorithms (used in <function>sort</function>) can be seen below: - </para> - <para> - <example> - <title><function>natsort</function> example</title> - <programlisting role="php"> -$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); - -sort($array1); -echo "Standard sorting\n"; -print_r($array1); - -natsort($array2); -echo "\nNatural order sorting\n"; -print_r($array2); - </programlisting> - </example> - </para> - <para> - The code above will generate the following output: - </para> - <para> - <informalexample> - <programlisting> -Standard sorting -Array -( - [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 -) - </programlisting> - </informalexample> - For more infomation see: Martin Pool's <ulink - url="&url.strnatcmp;">Natural Order String Comparison</ulink> - page. - </para> - <para> - See also <function>natcasesort</function>, - <function>strnatcmp</function> and - <function>strnatcasecmp</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.natcasesort"> - <refnamediv> - <refname>natcasesort</refname> - <refpurpose> - Sort an array using a case insensitive "natural order" algorithm - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>natcasesort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function implements a sort algorithm that orders - alphanumeric strings in the way a human being would. This is - described as a "natural ordering". - </para> - <para> - <function>natcasesort</function> is a case insensitive version of - <function>natsort</function>. See <function>natsort</function> - for an example of the difference between this algorithm and the - regular computer string sorting algorithms. - </para> - <para> - For more infomation see: Martin Pool's <ulink - url="&url.strnatcmp;">Natural Order String Comparison</ulink> - page. - </para> - <para> - See also <function>sort</function>, - <function>natsort</function>, - <function>strnatcmp</function> and - <function>strnatcasecmp</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.next"> - <refnamediv> - <refname>next</refname> - <refpurpose> - Advance the internal array pointer of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>next</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the array element in the next place that's pointed by the - internal array pointer, or <literal>FALSE</literal> if - there are no more elements. - </para> - <para> - <function>Next</function> behaves like - <function>current</function>, with one difference. It advances - the internal array pointer one place forward before returning the - 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, <function>next</function> returns <literal>FALSE</literal>. - <warning> - <para> - If the array contains empty elements, or elements that have a key - value of 0 then this function will return <literal>FALSE</literal> - for these elements as well. To properly traverse an array which - may contain empty elements or elements with key values of 0 see the - <function>each</function> function. - </para> - </warning> - </para> - <para> - See also: - <function>current</function>, <function>end</function>, - <function>prev</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.pos"> - <refnamediv> - <refname>pos</refname> - <refpurpose>Get the current element from an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>pos</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <simpara> - This is an alias for <function>current</function>. - </simpara> - <para> - See also: - <function>end</function>, <function>next</function>, - <function>prev</function> and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.prev"> - <refnamediv> - <refname>prev</refname> - <refpurpose>Rewind the internal array pointer</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>prev</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the array element in the previous place that's pointed by - the internal array pointer, or <literal>FALSE</literal> if there are no more - elements. - <warning> - <para> - If the array contains empty elements then this function will - return <literal>FALSE</literal> for these elements as well. - To properly traverse an array which may contain empty elements - see the <function>each</function> function. - </para> - </warning> - </para> - <para> - <function>Prev</function> behaves just like - <function>next</function>, except it rewinds the internal array - pointer one place instead of advancing it. - </para> - <para> - See also: <function>current</function>, <function>end</function>, - <function>next</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.range"> - <refnamediv> - <refname>range</refname> - <refpurpose> - Create an array containing a range of integers - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>range</function></funcdef> - <paramdef>int <parameter>low</parameter></paramdef> - <paramdef>int <parameter>high</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Range</function> returns an array of integers from - <parameter>low</parameter> to <parameter>high</parameter>, - inclusive. - </para> - <para> - See <function>shuffle</function> for an example of its use. - </para> - </refsect1> - </refentry> - - <refentry id="function.reset"> - <refnamediv> - <refname>reset</refname> - <refpurpose> - Set the internal pointer of an array to its first element - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>reset</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Reset</function> rewinds <parameter>array</parameter>'s - internal pointer to the first element. - </para> - <para> - <function>Reset</function> returns the value of the first array - element. - </para> - <para> - See also: <function>current</function>, - <function>each</function>, <function>next</function>, - and <function>prev</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.rsort"> - <refnamediv> - <refname>rsort</refname> - <refpurpose>Sort an array in reverse order</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>rsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array in reverse order (highest to lowest). - <example> - <title><function>Rsort</function> example</title> - <programlisting role="php"> -$fruits = array ("lemon", "orange", "banana", "apple"); -rsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[0] = orange -fruits[1] = lemon -fruits[2] = banana -fruits[3] = apple - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in reverse alphabetical order. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also: <function>arsort</function>, - <function>asort</function>, <function>ksort</function>, - <function>sort</function>, and <function>usort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.shuffle"> - <refnamediv> - <refname>shuffle</refname> - <refpurpose>Shuffle an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>shuffle</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function shuffles (randomizes the order of the elements in) - an array. You must use <function>srand</function> to seed this - function. - <example> - <title><function>Shuffle</function> example</title> - <programlisting role="php"> -$numbers = range (1,20); -srand ((double)microtime()*1000000); -shuffle ($numbers); -while (list (, $number) = each ($numbers)) { - echo "$number "; -} - </programlisting> - </example> - </para> - <para> - See also <function>arsort</function>, <function>asort</function>, - <function>ksort</function>, <function>rsort</function>, - <function>sort</function> and <function>usort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.sizeof"> - <refnamediv> - <refname>sizeof</refname> - <refpurpose>Get the number of elements in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>sizeof</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the number of elements in the array. - </para> - <para> - See also <function>count</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.sort"> - <refnamediv> - <refname>sort</refname> - <refpurpose>Sort an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>sort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array. Elements will be arranged from - lowest to highest when this function has completed. - <example> - <title><function>Sort</function> example</title> - <programlisting role="php"> -<?php - -$fruits = array ("lemon", "orange", "banana", "apple"); -sort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "fruits[".$key."] = ".$val; -} - -?> - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[0] = apple -fruits[1] = banana -fruits[2] = lemon -fruits[3] = orange - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in alphabetical order. - </para> - <para> - The optional second parameter <parameter>sort_flags</parameter> - may be used to modify the sorting behavior using theese valies: - </para> - <para> - Sorting type flags: - <itemizedlist> - <listitem> - <simpara>SORT_REGULAR - compare items normally</simpara> - </listitem> - <listitem> - <simpara>SORT_NUMERIC - compare items numerically</simpara> - </listitem> - <listitem> - <simpara>SORT_STRING - compare items as strings</simpara> - </listitem> - </itemizedlist> - </para> - <para> - See also: <function>arsort</function>, - <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>. - </para> - <note> - <para> - The second parameter was added in PHP 4. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.uasort"> - <refnamediv> - <refname>uasort</refname> - <refpurpose> - Sort an array with a user-defined comparison function and - maintain index association - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>uasort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>function <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. The comparison function - is user-defined. - </para> - <note> - <para> - Please see <function>usort</function> and - <function>uksort</function> for examples of user-defined - comparison functions. - </para> - </note> - <para> - See also: <function>usort</function>, <function>uksort</function>, - <function>sort</function>, <function>asort</function>, - <function>arsort</function>, <function>ksort</function> - and <function>rsort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.uksort"> - <refnamediv> - <refname>uksort</refname> - <refpurpose> - Sort an array by keys using a user-defined comparison function - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>uksort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>function <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function will sort the keys of an array using a - user-supplied comparison function. If the array you wish to sort - needs to be sorted by some non-trivial criteria, you should use - this function. - </para> - <para> - <example> - <title><function>Uksort</function> example</title> - <programlisting role="php"> -function cmp ($a, $b) { - if ($a == $b) return 0; - return ($a > $b) ? -1 : 1; -} - -$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); - -uksort ($a, "cmp"); - -while (list ($key, $value) = each ($a)) { - echo "$key: $value\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -20: twenty -10: ten -4: four -3: three - </programlisting> - </informalexample> - </para> - <para> - See also: <function>usort</function>, <function>uasort</function>, - <function>sort</function>, <function>asort</function>, - <function>arsort</function>, <function>ksort</function>, - <function>natsort</function> and <function>rsort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.usort"> - <refnamediv> - <refname>usort</refname> - <refpurpose> - Sort an array by values using a user-defined comparison function - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>usort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>string <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function will sort an array by its values using a - user-supplied comparison function. If the array you wish to sort - needs to be sorted by some non-trivial criteria, you should use - this function. - </para> - <para> - The comparison function must return an integer less than, equal - to, or greater than zero if the first argument is considered to - be respectively less than, equal to, or greater than the - second. If two members compare as equal, their order in the - sorted array is undefined. - </para> - <para> - <example> - <title><function>Usort</function> example</title> - <programlisting role="php"> -function cmp ($a, $b) { - if ($a == $b) return 0; - return ($a > $b) ? -1 : 1; -} - -$a = array (3, 2, 5, 6, 1); - -usort ($a, "cmp"); - -while (list ($key, $value) = each ($a)) { - echo "$key: $value\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -0: 6 -1: 5 -2: 3 -3: 2 -4: 1 - </programlisting> - </informalexample> - </para> - <note> - <para> - Obviously in this trivial case the <function>rsort</function> - function would be more appropriate. - </para> - </note> - <para> - <example> - <title> - <function>Usort</function> example using multi-dimensional array - </title> - <programlisting role="php"> -function cmp ($a, $b) { - return strcmp($a["fruit"],$b["fruit"]); -} - -$fruits[0]["fruit"] = "lemons"; -$fruits[1]["fruit"] = "apples"; -$fruits[2]["fruit"] = "grapes"; - -usort($fruits, "cmp"); - -while (list ($key, $value) = each ($fruits)) { - echo "\$fruits[$key]: " . $value["fruit"] . "\n"; -} - </programlisting> - </example> - </para> - <para> - When sorting a multi-dimensional array, $a and $b contain - references to the first index of the array. - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -$fruits[0]: apples -$fruits[1]: grapes -$fruits[2]: lemons - </programlisting> - </informalexample> - </para> - <para> - <warning> - <para> - The underlying quicksort function in some C libraries (such as - on Solaris systems) may cause PHP to crash if the comparison - function does not return consistent values. - </para> - </warning> - </para> - <para> - 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> - </refsect1> - </refentry> - - </reference> - -<!-- Keep this comment at the end of the file -Local variables: -mode: sgml -sgml-omittag:t -sgml-shorttag:t -sgml-minimize-attributes:nil -sgml-always-quote-attributes:t -sgml-indent-step:1 -sgml-indent-data:t -sgml-parent-document:nil -sgml-default-dtd-file:"../../manual.ced" -sgml-exposed-tags:nil -sgml-local-catalogs:nil -sgml-local-ecat-files:nil -End: ---> +<reference id="ref.array"> + <title>ë°°ì´í¨ì</title> + <titleabbrev>ë°°ì´</titleabbrev> + <partintro> + <simpara> + ì´ í¨ìë ë¤ìí ë°©ë²ì¼ë¡ ë°°ì´ì ë¤ë£¨ê³ , ìí¸ìì©í ì ìê² í´ ì¤ë¤. + ë°°ì´ì ë³ìë¤ì ì§í©ì ìí , ì²ë¦¬, ì¡°ì íëë° íìì ì´ë¤. + </simpara> + <simpara> + ì¼ì°¨ìë° ë¤ì°¨ì ë°°ì´ì ì¬ì©ì´ ê°ë¥íë©°, ì¬ì©ìë ë¤ë¥¸ í¨ìë¡ ë¶í° ìì±ë ì ìë¤. + ë°ì´í°ë² ì´ì¤ì 쿼리문ì¼ë¡ ë¶í° ë°°ì´ì ìì±ì ìí ëªëª í¹ë³í ë°ì´í°ë² ì´ì¤ í¸ë¤ë§ í¨ìê° ìê³ ëªëª í¨ìë¤ì 리í´ê°ì¼ë¡ ë°°ì´ì ë°ííë¤. + </simpara> + <para> + <function>is_array</function>, <function>explode</function>, + <function>implode</function>, <function>split</function> + ê·¸ë¦¬ê³ <function>join</function>ì 참조íë¼. + </para> + </partintro> + <refentry id="function.array"> + <refnamediv> + <refname>array</refname> + <refpurpose> + ë°°ì´ì ìì±íë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array</function> + </funcdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + íë¼ë¯¸í°ì ë°°ì´ì ë°ííë¤. íë¼ë¯¸í°ë<literal>=></literal> ì°ì°ì를 ê°ì§ ì¸ë±ì¤ë¡ 주ì´ì§ ìë ìë¤. + </para> + <para> + <note> + <para> + <function>Array</function> is a language construct used to + represent literal arrays, and not a regular function. + </para> + </note> + </para> + <para> + "index => values" 구문ì comma(,)ë¡ êµ¬ë¶ëë©°, ì¸ë±ì¤ì ê°ì ì ìíë¤. + ì¸ë±ì¤ê°ì¼ë¡ë 문ìí í¹ì ì«ìíì´ ì°ì¸ë¤. ì¸ë±ì¤ ê°ì´ ìëµëì ì ê²½ì° + ì ì 0ì¼ë¡ ììëë ì¸ë±ì¤ê° ìëì¼ë¡ ìì±ëë¤. ì¸ë±ì¤ê° ì ìë¼ë©´ + ë¤ìì ìì±ëë ì¸ë±ì¤ë (ê°ì¥ í° ì¸ë±ì¤ê° + 1) ì ê°ì´ ëë¤. + ëê°ì ëì¼í ì¸ë±ì¤ê° ì ìëìì ê²½ì°, ë§ì§ë§ ê°ì´ ì²ì ê°ì ë®ì´ì°ê² ë¨ì ì ìíë¼. + </para> + <para> + ë¤ìì ìë 2ì°¨ì ë°°ì´ì ìì±íë ë°©ë²ê³¼, associative ë°°ì´ì í¤(key)ê°ì ì§ì íë ë°©ë² + , ì«ì ì¸ë±ì¤ê° ë°°ì´ìì ì´ë¤ ê·ì¹ì¼ë¡ ìì± ëëì§ë¥¼ ì¤ëª íë¤. + <example> + <title> + <function>Array</function> example</title> + <programlisting role="php"> +$fruits = array ( + "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"), + "numbers" => array (1, 2, 3, 4, 5, 6), + "holes" => array ("first", 5 => "second", "third") +); + </programlisting> + </example> + </para> + <para> + <example> + <title> + <function>Array</function>í¨ììì ì¸ë±ì¤ì ìëìì± + </title> + <programlisting role="php"> +$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); +print_r($array); + </programlisting> + </example> + ë¤ìì ì¶ë ¥í ê²ì´ë¤. : + <informalexample> + <programlisting> +Array +( + [0] => 1 + [1] => 1 + [2] => 1 + [3] => 13 + [4] => 1 + [8] => 1 + [9] => 19 +) + </programlisting> + </informalexample> + ì¸ë±ì¤ '3'ì ëí´ ê°ì´ ëë² ì ìëìì¼ë©°, ì¸ë±ì¤ '3'ì í´ë¹íë ìµì¢ ê°ì ë§ì§ë§ì ì ìë 13ì´ ëë¤. + ì¸ë±ì¤ '4'ê° ì ìë íì ì¸ë±ì¤ '8' ì´ ì ìëìê³ ë¤ìì ìì±ë ì¸ë±ì¤(ê° 19를 ê°ì§ë¤)ë + ê°ì¥ í° ì¸ë±ì¤ ê°ì´ 8ì´ìì¼ë¯ë¡ 9ê° ëë¤ë ì ì ì ìíë¼. + </para> + <para> + ì¼ì°¨ì ë°°ì´ ìì±ì ì. + <example> + <title> + <function>Array</function>ììì 1ì°¨ìë°°ì´ ì¸ë±ì¤ + </title> + <programlisting role="php"> + $firstquarter = array(1 => 'January', 'February', 'March'); + print_r($firstquarter); + </programlisting> + </example> + ë¤ìì ì¶ë ¥í ê²ì´ë¤. : + <informalexample> + <programlisting> +Array +( + [1] => 'January' + [2] => 'February' + [3] => 'March' +) + </programlisting> + </informalexample> + </para> + <para> + <function>list</function>를 ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-count-values"> + <refnamediv> + <refname>array_count_values</refname> + <refpurpose>ë°°ì´ ê°ì ì를 ì¼ë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_count_values</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_count_values</function> ë <parameter>input</parameter> ë°°ì´ì ê°ì + í¤ë¡ ê°ê³ ê·¸ ê°ë¤ì ë¹ë를 ê°ì¼ë¡ ê°ë ë°°ì´ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_count_values</function>ì</title> + <programlisting role="php"> +$array = array (1, "hello", 1, "world", "hello"); +array_count_values ($array); // array (1=>2, "hello"=>2, "world"=>1) ì ë°ííë¤. + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-diff"> + <refnamediv> + <refname>array_diff</refname> + <refpurpose>ë°°ì´ì ì°¨ì´ì ê³ì°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_diff</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional> ...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_diff</function>ë ì¸ìë¡ ì¨ <parameter>array1</parameter>ì´ì¸ì + ë°°ì´ì ê°ê³¼ ì¤ë³µëì§ ìë <parameter>array1</parameter>ì ê°ì í¬í¨íë ë°°ì´ì ë°ííë¤. + í¤(keys)ë ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_diff</function> ì</title> + <programlisting role="php"> +$array1 = array ("a" => "green", "red", "blue"); +$array2 = array ("b" => "green", "yellow", "red"); +$result = array_diff ($array1, $array2); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname> ê° <literal>array ("blue");</literal>를 ê°ì§ê² ëë¤. + </para> + <para> + <function>array_intersect</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-flip"> + <refnamediv> + <refname>array_flip</refname> + <refpurpose>Flip all the values of an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_flip</function> + </funcdef> + <paramdef>array <parameter>trans</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_flip</function> returns an array in flip order. + </para> + <para> + <example> + <title> + <function>Array_flip</function> example</title> + <programlisting role="php"> +$trans = array_flip ($trans); +$original = strtr ($str, $trans); + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-intersect"> + <refnamediv> + <refname>array_intersect</refname> + <refpurpose>ë°°ì´ì ì¤ë³µì ê³ì°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_intersect</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional> ...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_intersect</function>ë ì¸ìë¡ ì¨ ëª¨ë ë°°ì´ì ì¡´ì¬íë <parameter>array1</parameter>ì ê°ì 모ë í¬í¨íë ë°°ì´ì ë°ííë¤. + í¤ë ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_intersect</function> ì</title> + <programlisting role="php"> +$array1 = array ("a" => "green", "red", "blue"); +$array2 = array ("b" => "green", "yellow", "red"); +$result = array_intersect ($array1, $array2); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname>ë <literal>array ("a" + => "green", "red");</literal>ì´ ëë¤. + </para> + <para> + <function>array_diff</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-keys"> + <refnamediv> + <refname>array_keys</refname> + <refpurpose>ë°°ì´ì 모ë í¤ê°ì ë°ííë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_keys</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>search_value</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_keys</function> ë <parameter>input</parameter> ë°°ì´ë¡ ë¶í° ì«ìíê³¼ 문ìíì í¤ë¥¼ ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ìµì ì¸ <parameter>search_value</parameter>ì´ ì§ì ëë¤ë©´, ê·¸ ê°ì ê°ì§ë í¤ë§ì´ ë°íëê³ ìëµëë©´ <parameter>input</parameter> ì 모ë í¤ê° ë°°ì´ë¡ ë°íëë¤. + </para> + <para> + <example> + <title> + <function>Array_keys</function> ì</title> + <programlisting role="php"> +$array = array (0 => 100, "color" => "red"); +array_keys ($array); // array (0, "color") ì ë°ííë¤. + +$array = array ("blue", "red", "green", "blue", "blue"); +array_keys ($array, "blue"); // array (0, 3, 4) ì ë°ííë¤. + </programlisting> + </example> + </para> + <note> + <para> + ì´ í¨ìë PHP 4ìì ì¶ê°ëìì¼ë©°, ìëë ì¬ì í PHP3ì ì¬ì©íë ì¬ì©ì를 ìí ì´ í¨ìì 구íë¶ë¶ì´ë¤. + <example> + <title> + PHP 3 ì¬ì©ìë¤ì ìí <function>array_keys</function>ì 구í + </title> + <programlisting role="php"> +function array_keys ($arr, $term="") { + $t = array(); + while (list($k,$v) = each($arr)) { + if ($term && $v != $term) + continue; + $t[] = $k; + } + return $t; +} + </programlisting> + </example> + </para> + </note> + <para> + <function>array_values</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-merge"> + <refnamediv> + <refname>array_merge</refname> + <refpurpose>ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_merge</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_merge</function> ë ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë©°, + ê°ì ì´ì ë°°ì´ì ëì ë¶ì´ ì¶ê°ëë¤. ê·¸ 결과를 ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ë§ì½ ì ë ¥ë ë°°ì´ì´ ê°ì 문ìì´ í¤ë¥¼ ê°ì§ë¤ë©´, ê·¸ í¤ì ëí´ ëì¤ì ì¨ ê°ì´ ì´ì ì ê°ì ëì²´íë¤. + ê·¸ë¬ë ì ë ¥ë ë°°ì´ì´ ê°ì ì«ì í¤ë¥¼ ê°ì§ë¤ë©´, ëì¤ ê°ì´ ì²ìê°ì ëì²´íì§ ìê³ ëì¤ ê°ì ë°°ì´ì ë¤ì ì¶ê°ê° ëë¤. + </para> + <para> + <example> + <title> + <function>array_merge</function> ì</title> + <programlisting role="php"> +$array1 = array ("color" => "red", 2, 4); +$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4); +array_merge ($array1, $array2); + </programlisting> + </example> + </para> + <para> + ê²°ê³¼ë¡ ëíëë ë°°ì´ì <literal>array("color" => "green", 2, 4, + "a", "b", "shape" => "trapezoid", 4)</literal>ì´ ëë¤. + </para> + <para> + <function>array_merge_recursive</function>ì ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-merge-recursive"> + <refnamediv> + <refname>array_merge_recursive</refname> + <refpurpose>ì¬ê·ì ì¼ë¡ ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_merge_recursive</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_merge_recursive</function> ë ëê° ì´ìì ë°°ì´ ìì를 ë³í©íì¬ ê°ì ì´ì ë°°ì´ì ì¶ê°íê³ ì´ë¥¼ ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ì ë ¥ë ë°°ì´ì ê°ì 문ìì´ í¤ê° ìì¼ë©´, ì´ í¤ë ë°°ì´ë¡ í©ì³ì§ê³ ì´ë ì¬ê·ì ì¼ë¡ ì§íëë¤. + ë°°ì´ì ê°ì¼ë¡ ê°ë ê²½ì° ê°ì ë°©ìì¼ë¡ ê° ê°ì ë°°ì´ì ë³í©íë¤. + ê·¸ë¬ë ë°°ì´ì´ ê°ì ì«ì í¤ë¥¼ ê°ì§ë¤ë©´ ëì¼ ì«ìí¤ì ê°ì ë®ì´ì°ë ê²ì´ ìëë¼ ì´ì ë°°ì´ì ë¤ì ì¶ê° ëë¤. + </para> + <para> + <example> + <title> + <function>Array_merge_recursive</function> ì</title> + <programlisting role="php"> +$ar1 = array ("color" => array ("favorite" => "red"), 5); +$ar2 = array (10, "color" => array ("favorite" => "green", "blue")); +$result = array_merge_recursive ($ar1, $ar2); + </programlisting> + </example> + </para> + <para> + <literal>array ("color" => array + ("favorite" => array ("red", "green"), "blue"), 5, 10)</literal>ì 결과를 ê°ëë¤. + </para> + <para> + <function>array_merge</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-multisort"> + <refnamediv> + <refname>array_multisort</refname> + <refpurpose>ì¬ë¬ê°ì ë°°ì´ í¹ì ë¤ì°¨ì ë°°ì´ì ì ë ¬íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>bool <function>array_multisort</function> + </funcdef> + <paramdef>array <parameter>ar1</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>arg</optional> + </parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_multisort</function> ë ë¤ì¤ ë°°ì´ì ëí´ì ì¬ë¬ê°ì ë°°ì´ì íë²ì ì ë ¬íê±°ë ë¤ì°¨ì ë°°ì´ìì ë´ë¶ì í¬í¨ëë ê°ê°ê°ì ë°°ì´ì ì ë ¬íëë° ì¬ì©ëë¤. + ì ë ¬ë ë í¤ê°ë ì ì§ëë¤. + </para> + <para> + ì ë ¥ë ë°°ì´ì íì ìí´ ì ë ¬íë í ì´ë¸ì ì´ê³¼ë ê°ì´ ìê°í ì ìë¤. - ì´ë SQLì ORDER BYì ê³¼ ê·¸ 기ë¥ì´ ì ì¬íë¤. + 첫ë²ì§¸ ì¤ë ë°°ì´ì´ 먼ì ì ë ¬ ëë¤. ë°°ì´ì í(ê°) + </para> + <para> + ì´ í¨ìì 매ê°ë³ì 구조ë ì½ê° ë í¹íì§ë§, ì ì°íë¤. + ì²ìì 매ê°ë³ìë ë°°ì´ì´ì´ì¼ íë©°, ë¤ìì ëì¤ë ê°ê°ì 매ê°ë³ìë + ë°°ì´ì´ê±°ë í¹ì ë¤ìì ê¸ëê·¸ 리ì¤í¸ì ìë ì ë ¬ íëê·¸ì¼ ì ìë¤. + </para> + <para> + ì ë ¬ ë°©ë² íëê·¸: + <itemizedlist> + <listitem> + <simpara>SORT_ASC - ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬</simpara> + </listitem> + <listitem> + <simpara>SORT_DESC - ë´ë¦¼ì°¨ìì¼ë¡ ì ë ¬</simpara> + </listitem> + </itemizedlist> + </para> + <para> + ì ë ¬ íí íëê·¸: + <itemizedlist> + <listitem> + <simpara>SORT_REGULAR - íµìì ì¼ë¡ ìì´í ì ë¹êµ</simpara> + </listitem> + <listitem> + <simpara>SORT_NUMERIC - ìì¹ë¡ì ìì´í ì ì ë ¬</simpara> + </listitem> + <listitem> + <simpara>SORT_STRING - 문ìì´ë¡ì ìì´í ì ì ë ¬</simpara> + </listitem> + </itemizedlist> + </para> + <para> + ê°ê°ì ë°°ì´ìë ê°ì íì ì ì ë ¬ íëê·¸ ëê°ê° ì§ì ë ì ìë¤. + ë°°ì´ ë§¤ê°ë³ìì ëª ê¸°ë ì ë ¬ íëê·¸ë ë¨ì§ ê·¸ ë°°ì´ìë§ ì ì©ëë¤ + - ì´ë ìë¡ì´ ë°°ì´ì´ 매ê°ë³ìë¡ ì¤ê¸° ì ì 기본ê°ì¸ SORT_ASCì + SORT_REGULAR ë¡ ë¦¬ì ëë¤. + </para> + <para> + ì±ê³µìì ì°¸ì ë°ííë©°, ì¤í¨ìì ê±°ì§ì ë°ííë¤. + </para> + <para> + <example> + <title>Sorting multiple arrays</title> + <programlisting role="php"> +$ar1 = array ("10", 100, 100, "a"); +$ar2 = array (1, 3, "2", 1); +array_multisort ($ar1, $ar2); + </programlisting> + </example> + </para> + <para> + ì를 ë¤ì´, ì ë ¬ íì ì²ì ë°°ì´ì 10,"a",100,100 ì í¬í¨íë¤. + ëë²ì§¸ ë°°ì´ì 1,1,2,"3" ì í¬í¨íë¤. + 첫ë²ì§¸ ë°°ì´ì ê°ê°ì ìí¸ë¦¬(100 ê³¼ 100)ì ëìëë + ëë²ì§¸ ë°°ì´ì ìí¸ë¦¬ ëí ì ë ¬ëë¤. + The entries in the second array corresponding to the identical + entries in the first array (100 and 100) were sorted as well. + </para> + <para> + <example> + <title>ë¤ì°¨ì ë°°ì´ì ì ë ¬</title> + <programlisting role="php"> +$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); +array_multisort ($ar[0], SORT_ASC, SORT_STRING, + $ar[1], SORT_NUMERIC, SORT_DESC); + </programlisting> + </example> + </para> + <para> + ì´ ììì ì ë ¬ í ì²ì ë°°ì´ì 10, 100, 100, "a"(ì´ë 문ìì´ë¡ + ì²ë¦¬ëì´ ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬.), ê·¸ë¦¬ê³ ëë²ì§¸ ë°°ì´ì + 1, 3, "2", 1 (ì«ìë¡ ì²ë¦¬ëì´ ë´ë¦¼ì°¨ìì¼ë¡ ì ë ¬)ì ê°ëë¤. + </para> + </refsect1> + </refentry> + <refentry id="function.array-pad"> + <refnamediv> + <refname>array_pad</refname> + <refpurpose> + 주ì´ì§ ê°ì 길ì´ë§í¼ ë°°ì´ì ì±ì´ë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_pad</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int <parameter>pad_size</parameter> + </paramdef> + <paramdef>mixed <parameter>pad_value</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_pad</function> returns a copy of the + <parameter>pad_value</parameter>ì ê°ì¼ë¡ <parameter>pad_size</parameter> 길ì´ë§í¼ ì±ìì§ <parameter>input</parameter>ë°°ì´ì ë³µì¬ë³¸ì ë°ííë¤. + <parameter>pad_size</parameter> ê° ìì ê°ì´ë©´, ë°°ì´ì ì¤ë¥¸ìª½ì´ ì±ìì§ê³ , ììë¼ë©´, ì¼ìª½ì´ ì±ìì§ë¤. + <parameter>pad_size</parameter> ê°ì´ <parameter>input</parameter> ë°°ì´ì 길ì´ë³´ë¤ ìê±°ë ê°ë¤ë©´, í¨ë©(padding)ì ì¼ì´ëì§ ìëë¤. + </para> + <para> + <example> + <title> + <function>Array_pad</function> ì</title> + <programlisting role="php"> +$input = array (12, 10, 9); + +$result = array_pad ($input, 5, 0); +// ê²°ê³¼ë array (12, 10, 9, 0, 0) ì´ë¤. + +$result = array_pad ($input, -7, -1); +// ê²°ê³¼ë array (-1, -1, -1, -1, 12, 10, 9) ì´ë¤. + +$result = array_pad ($input, 2, "noop"); +// pad ëì§ ìëë¤. + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-pop"> + <refnamediv> + <refname>array_pop</refname> + <refpurpose>ë°°ì´ ëì ìì를 ë½ìë¸ë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_pop</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_pop</function> ì <parameter>array</parameter>ì ë§ì§ë§ ê°ì ë½ì ë´ê³ ê·¸ ê°ì ë°ííë©°, <parameter>array</parameter>ì 길ì´ë¥¼ ìì íëë§í¼ ì¤ì¸ë¤. + </para> + <para> + <example> + <title> + <function>Array_pop</function> ì</title> + <programlisting role="php"> +$stack = array ("orange", "apple", "raspberry"); +$fruit = array_pop ($stack); + </programlisting> + </example> + </para> + <para> + ì´ ì´í, <varname>$stack</varname> ì "orange" ì "apple" ë¨ 2ê°ì ììë§ ê°ì§ë¤: + <varname>$fruit</varname> ë "raspberry" ì ê°ì ê°ëë¤. + </para> + <para> + <function>array_push</function>, + <function>array_shift</function>, ê·¸ë¦¬ê³ + <function>array_unshift</function> ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-push"> + <refnamediv> + <refname>array_push</refname> + <refpurpose> + ë°°ì´ ëì íë í¹ì ê·¸ ì´ìì ìì를 ë£ëë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_push</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_push</function> ë <parameter>array</parameter> ì ì¤íê³¼ ê°ì´ ë¤ë£¨ë©°, <parameter>array</parameter>ì ëì ì ë¬ëì´ì§ ê°ì ì§ì´ ë£ëë¤. + <parameter>array</parameter>ì 길ì´ë ì§ì´ë£ì´ì§ ê°ë¤ì ìë§í¼ ëì´ëë©° ë¤ìê³¼ ê°ì í¨ê³¼ê° ìë¤. + <programlisting role="php"/> + ë°ë³µëë ê°ê°ì <parameter>var</parameter>ì ëí´ + $array[] = $var; + </para> + <para> + ë°°ì´ì ìë¡ ì¶ê°ë ììì ìê° ë°íëë¤. + </para> + <para> + <example> + <title> + <function>Array_push</function> ì</title> + <programlisting role="php"> +$stack = array (1, 2); +array_push ($stack, "+", 3); + </programlisting> + </example> + </para> + <para> + ì´ ììì <varname>$stack</varname>ì 4ê°ì ìì(1,2,"+",3)를 ê°ë ë°°ì´ì´ ëë¤. + </para> + <para> + <function>array_pop</function>, + <function>array_shift</function>, + <function>array_unshift</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-rand"> + <refnamediv> + <refname>array_rand</refname> + <refpurpose> + ë°°ì´ìì íë í¹ì ê·¸ ì´ìì ììì ìì를 ê°ì ¸ì¨ë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_rand</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>num_req</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_rand</function>ì ë°°ì´ì ììì¤ ììë¡ íë í¹ì ì¬ë¬ê°ì ìì를 ê°ì ¸ì¬ ë ì ì©íë¤. + <parameter>input</parameter> ë°°ì´ì íìë¡ íê³ , ì í ì¸ìë¡ <parameter>num_req</parameter>ì´ ì¬ ì ìëë°, + ë½ìë´ê³ ì¶ì ì리먼í¸ì ì를 ì§ì í ì ìê³ í¹ë³í ì§ì ëì§ ììì ëì 기본 ê°ì 1ì´ë¤. + </para> + <para> + ë¨ì§ íëì ììë§ ê°ì ¸ì¤ë©´, <function>array_rand</function>ë ìì ììì ëí í¤ë¥¼ ë°ííë©°, ììì ì¬ë¬ ìì를 ê°ì ¸ì¬ ê²½ì° ê°ê°ì ìì ììì ëí í¤ì ë°°ì´ì ë°ííë¤. + ì´ë ê² í¨ì¼ë¡ì ë°°ì´ìì ë¶í° ììë¡ ê° ë¿ë§ ìëë¼ í¤ë¥¼ ê°ì ¸ ì¬ ì ìë¤. + </para> + <para> + ëì ìì±ì(rand number generator)를 ë§ë¤ê¸° ìí´<function>srand</function> í¨ì를 í¸ì¶íëê²ì ìì§ ë§ë¼. + </para> + <para> + <example> + <title> + <function>Array_rand</function> ì</title> + <programlisting role="php"> +srand ((double) microtime() * 10000000); +$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); +$rand_keys = array_rand ($input, 2); +print $input[$rand_keys[0]]."\n"; +print $input[$rand_keys[1]]."\n"; + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-reverse"> + <refnamediv> + <refname>array_reverse</refname> + <refpurpose> + ê° ì리먼í¸ë¥¼ ììì¼ë¡ ì ë ¬í ë°°ì´ì ë°ííë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_reverse</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_reverse</function>ë ì ë ¥ì¼ë¡ + <parameter>array</parameter> 를 ê°ì§ë©° ì리먼í¸ë¤ì´ + ììì¼ë¡ ì ë ¬ë ìë¡ì´ ë°°ì´ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_reverse</function> ì</title> + <programlisting role="php"> +$input = array ("php", 4.0, array ("green", "red")); +$result = array_reverse ($input); + </programlisting> + </example> + </para> + <para> + ì´ ìë <varname>$result</varname> ê° <literal>array + (array ("green", "red"), 4.0, "php")</literal>를 ê°ì§ë¤.. + </para> + </refsect1> + </refentry> + <refentry id="function.array-shift"> + <refnamediv> + <refname>array_shift</refname> + <refpurpose> + ë°°ì´ì 맨 ìì ìë ìì를 꺼ë´ê³ ê·¸ ìì를 ìì íë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_shift</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_shift</function> ë <parameter>array</parameter>ì + 첫ë²ì§¸ ê°ì 꺼ë´ê³ ê·¸ êº¼ë¸ ê°ì ë°ííë©°, <parameter>array</parameter>ì + 첫ë²ì§¸ ì리먼í¸ë¥¼ ìì íê³ ë¤ë¥¸ 모ë ì리먼í¸ë¥¼ í칸 ìì¼ë¡ ì´ëìí¨ë¤. + </para> + <para> + <example> + <title> + <function>Array_shift</function> ì</title> + <programlisting role="php"> +$args = array ("-v", "-f"); +$opt = array_shift ($args); + </programlisting> + </example> + </para> + <para> + ì´ë <varname>$args</varname> ê° "-f" ì ì리먼í¸ë¥¼ ê°ê³ , + <varname>$opt</varname>ë "-v"ì ê°ì ê°ëë¤. + </para> + <para> + <function>array_unshift</function>, + <function>array_push</function>, ê·¸ë¦¬ê³ + <function>array_pop</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-slice"> + <refnamediv> + <refname>array_slice</refname> + <refpurpose>ë°°ì´ì ì¼ë¶ë¥¼ ì¶ì¶íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_slice</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter>offset</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>length</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_slice</function> ë ì¼ë ¨ì ì리먼í¸ë¥¼ + <parameter>offset</parameter> and <parameter>length</parameter>ì + 매ê°ë³ìì ë°ë¼ <parameter>array</parameter> ë¡ë¶í° ë°ííë¤. + </para> + <para> + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë©´, ìíì¤ë + <parameter>array</parameter>ì ì«ìì í´ë¹íë ìµì (offset)ìì ë¶í° + ììíë¤. ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + ìíì¤ë <parameter>array</parameter>ì ëììë¶í° ê·¸ ìë§í¼ + ë¨ì´ì§ ê³³ìì ë¶í° ììíë¤. + </para> + <para> + ë§ì½ <parameter>length</parameter>ì´ ì£¼ì´ì§ê³ ìì ê°ì´ë¼ë©´, + ìíì¤ë ê·¸ ìë§í¼ì ì리먼í¸ê° ë ê²ì´ë¤. + ë§ì½ <parameter>length</parameter>ê° ì£¼ì´ì§ê³ ìì ê°ì´ë¼ë©´, + ìíì¤ë ë°°ì´ì ëìì ë¶í° ê·¸ ê°¯ìë§í¼ì ì리먼í¸ê° ë ê²ì´ë¤. + ìëµì´ ëë¤ë©´, ìíì¤ë <parameter>offset</parameter>ììë¶í° + <parameter>array</parameter> ëê¹ì§ì ì리먼í¸ë¥¼ 모ë ê°ì§ê² ëë¤. + </para> + <para> + <example> + <title> + <function>Array_slice</function> ì</title> + <programlisting role="php"> +$input = array ("a", "b", "c", "d", "e"); + +$output = array_slice ($input, 2); // "c", "d", ê·¸ë¦¬ê³ "e" 를 ë°ííë¤. +$output = array_slice ($input, 2, -1); // "c", "d" 를 ë°ííë¤. +$output = array_slice ($input, -2, 1); // "d" 를 ë°ííë¤. +$output = array_slice ($input, 0, 3); // "a", "b", ê·¸ë¦¬ê³ "c" 를 ë°ííë¤. + </programlisting> + </example> + </para> + <para> + <function>array_splice</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-splice"> + <refnamediv> + <refname>array_splice</refname> + <refpurpose> + ë°°ì´ì ì¼ë¶ë¥¼ ìì íê³ , ê·¸ ìì¹ì ë¤ë¥¸ ë´ì©ì ë¼ì ë£ëë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_splice</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int <parameter>offset</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>length</optional> + </parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>replacement</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_splice</function>ë <parameter>input</parameter> + ë°°ì´ë¡ ë¶í° <parameter>offset</parameter> ì <parameter>length</parameter>ë¡ ì í´ì§ + ì린먼í¸ë¥¼ ìì íê³ , <parameter>replacement</parameter>ë°°ì´ì´ ì ê³µëë¤ë©´ + ì´ë¥¼ ì ê³µë ë°°ì´ì¼ë¦¬ ì리먼í¸ë¡ ëì²´ìí¨ë¤. + </para> + <para> + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + ìì ë¶ë¶ì ììì <parameter>input</parameter> ë°°ì´ì + ì²ì ë¶í° ê·¸ í´ë¹íë ìµì ê¹ì§ì´ë¤. + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + <parameter>input</parameter> ë°°ì´ì ëìì ë¶í° ìµì ë§í¼ ë¨ì´ì§ + ê³³ìì ë¶í° ììëë¤. + </para> + <para> + ë§ì½ <parameter>length</parameter>ì´ ìëµëë©´, + <parameter>offset</parameter>ììë¶í° ë°°ì´ì ëê¹ì§ì 모ë + ì리먼í¸ë¥¼ ìì íë¤. + ë§ì½ <parameter>length</parameter>ê° ì ìëê³ ìì ê°ì ê°ëë¤ë©´, + ê·¸ ì ë§í¼ì ì리먼í¸ê° ìì ëë¤. + <parameter>length</parameter>ê° ì ìëê³ ìì ê°ì ê°ëë¤ë©´, + ìì ëë ë¶ë¶ì ëì´ ë°°ì´ì ëììë¶í°ì ì«ìê° ëë¤. + í: <parameter>replacement</parameter>ê° ì§ì ëì´ ìì ë, + <parameter>offset</parameter>ììë¶í° ë°°ì´ì ëê¹ì§ì + 모ë ì리먼í¸ë¥¼ ìì íë ¤ë©´, <parameter>length</parameter>ëì + <literal>count($input)</literal>ì ì¬ì©íë¼. + </para> + <para> + <parameter>replacement</parameter> ë°°ì´ì´ ì§ì ëì´ ìì¼ë©´, + ìì ë ì리먼í¸ë ì´ ë°°ì´ì ì리먼í¸ë¡ ëì²´ëë¤. + + If <parameter>replacement</parameter> array is specified, then + the removed elements are replaced with elements from this array. + If <parameter>offset</parameter> and + <parameter>length</parameter> are such that nothing is removed, + then the elements from the <parameter>replacement</parameter> + array are inserted in the place specified by the + <parameter>offset</parameter>. Tip: if the replacement is just + one element it is not necessary to put <literal>array()</literal> + around it, unless the element is an array itself. + </para> + <para> + The following equivalences hold: + <programlisting> +array_push ($input, $x, $y) array_splice ($input, count ($input), 0, + array ($x, $y)) +array_pop ($input) array_splice ($input, -1) +array_shift ($input) array_splice ($input, 0, 1) +array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y)) +$a[$x] = $y array_splice ($input, $x, 1, $y) + </programlisting> + </para> + <para> + Returns the array consisting of removed elements. + </para> + <para> + <example> + <title> + <function>Array_splice</function> examples</title> + <programlisting role="php"> +$input = array ("red", "green", "blue", "yellow"); + +array_splice ($input, 2); // $input is now array ("red", "green") +array_splice ($input, 1, -1); // $input is now array ("red", "yellow") +array_splice ($input, 1, count($input), "orange"); + // $input is now array ("red", "orange") +array_splice ($input, -1, 1, array("black", "maroon")); + // $input is now array ("red", "green", + // "blue", "black", "maroon") + </programlisting> + </example> + </para> + <para> + See also <function>array_slice</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.array-unique"> + <refnamediv> + <refname>array_unique</refname> + <refpurpose>ë°°ì´ë¡ë¶í° ì¤ë³µë ê°ì ì ê±°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_unique</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_unique</function> ë ì ë ¥ì¼ë¡ + <parameter>array</parameter>를 ì¶ë ¥ì¼ë¡ë ì¤ë³µë ê°ì´ ìë + ë°°ì´ì ë°ííë¤. + í¤ê°ì ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_unique</function> ì</title> + <programlisting role="php"> +$input = array ("a" => "green", "red", "b" => "green", "blue", "red"); +$result = array_unique ($input); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname> ë <literal>array ("a" => + "green", "red", "blue");</literal>ì ê°ì ê°ì§ë ê²°ê³¼ê° ëë¤. + </para> + </refsect1> + </refentry> + <refentry id="function.array-unshift"> + <refnamediv> + <refname>array_unshift</refname> + <refpurpose> + ë°°ì´ì 맨 ìì í ê°ë ê·¸ ì´ìì ìì를 첨ê°íë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_unshift</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_unshift</function> ë <parameter>array</parameter> ì + ìì ì ë¬ëì´ì§ ìì를 첨ê°íë¤. + ììì 목ë¡ì ì ì²´ì ì¼ë¡ í리íëëê³ , ê·¸ ê²°ê³¼ í리íëë ììë + ëì¼í ììë¡ ë¨ììê² ëë¤. + <function>Array_unshift</function> prepends passed elements to + the front of the <parameter>array</parameter>. Note that the list + of elements is prepended as a whole, so that the prepended + elements stay in the same order. + </para> + <para> + <parameter>array</parameter> ì ìë¡ì´ ììì ì를 ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_unshift</function> ì</title> + <programlisting role="php"> +$queue = array ("p1", "p3"); +array_unshift ($queue, "p4", "p5", "p6"); + </programlisting> + </example> + </para> + <para> + <varname>$queue</varname> ê° + "p4", "p5", "p6", "p1", and "p3", 5ê°ì ìì를 ê°ë ê²°ê³¼ê° ëë¤. + </para> + <para> + <function>array_shift</function>, + <function>array_push</function>, ê·¸ë¦¬ê³ + <function>array_pop</function>를 ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-values"> + <refnamediv> + <refname>array_values</refname> + <refpurpose>ë°°ì´ì 모ë ê°ë¤ì ë°ííë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_values</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_values</function> ë + <parameter>input</parameter> ë°°ì´ì 모ë ê°ë¤ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_values</function> ì</title> + <programlisting role="php"> +$array = array ("size" => "XL", "color" => "gold"); +array_values ($array); // returns array ("XL", "gold") + </programlisting> + </example> + </para> + <note> + <para> + ì´ í¨ìë PHP 4 ìì ì¶ê°ëìê³ , ë¤ìì PHP3ììì 구íì´ë¤. + <example> + <title> + PHP 3 ì¬ì©ì를 ìí<function>array_values</function> ì 구í + </title> + <programlisting role="php"> +function array_values ($arr) { + $t = array(); + while (list($k, $v) = each ($arr)) { + $t[] = $v; + return $t; + } +} + </programlisting> + </example> + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.array-walk"> + <refnamediv> + <refname>array_walk</refname> + <refpurpose> + ë°°ì´ì ê°ê°ì ììì í¹ì í¨ì를 ì ì©íì¬ ìííë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_walk</function> + </funcdef> + <paramdef>array <parameter>arr</parameter> + </paramdef> + <paramdef>string <parameter>func</parameter> + </paramdef> + <paramdef>mixed <parameter>userdata</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <simpara> + í¨ì <parameter>func</parameter> ì <parameter>arr</parameter>ì + ê°ê°ì ììì ì ì©íë¤. + <parameter>func</parameter> ì ë°°ì´ ê°ì´ 첫ë²ì§¸ ì¸ìë¡, + ë°°ì´ í¤ë¤ ëë²ì§¸ ì¸ìë¡ ì ë¬ëë¤. + <parameter>userdata</parameter>ê° ì£¼ì´ì§ë©´ ì´ë í¨ìì ì¸ë²ì§¸ ì¸ìë¡ + ì ë¬ëë¤. + </simpara> + <simpara> + <parameter>func</parameter> ì´ ëê° í¹ì 3ê° ì´ìì 매ê°ë³ìê° íìíë©´, + <parameter>userdata</parameter> ì ë°ë¼ì + <function>array_walk</function>ì´ <parameter>func</parameter>를 + í¸ì¶í ëë§ë¤ ë§¤ë² ê²½ê³ ê° ë°ìíë¤. + ì´ë° ê²½ê³ ë <function>array_walk</function> ì '@' 기í¸ë¥¼ ë§ë¶ì´ê±°ë + <function>error_reporting</function> 를 ì¬ì©í¨ì¼ë¡ì ìíë ì ìë¤. + </simpara> + <note> + <para> + <parameter>func</parameter>ì´ ì¤ì ê°ì¼ë¡ ëìí íìê° ìë¤ë©´, + <parameter>func</parameter>ì 첫ë²ì§¸ 매ê°ë³ìë 참조ì ìí + ì ë¬ì´ ëì´ì¼ íë¤. + ê·¸ë¬ë©´, ììì ê°í´ì§ 모ë ë³íê° ë°°ì´ ìì²´ì ë°ìëë¤. + </para> + </note> + <note> + <para> + í¤ì userdata 를 <parameter>func</parameter>ì ì ë¬íë ê²ì + 4.0 ìì ì¶ê°ëìë¤. + </para> + <para> + PHP 4 ììë <function>reset</function> ì í¸ì¶ì´ íìì ì¼ë¡ íìíë¤. + ìëíë©´, <function>array_walk</function> ë 기본ì ì¼ë¡ ë°°ì´ì 리ì + ìí¤ì§ ì기 ë문ì´ë¤. + </para> + </note> + <para> + <example> + <title> + <function>Array_walk</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); + +function test_alter (&$item1, $key, $prefix) { + $item1 = "$prefix: $item1"; +} + +function test_print ($item2, $key) { + echo "$key. $item2<br>\n"; +} + +array_walk ($fruits, 'test_print'); +reset ($fruits); +array_walk ($fruits, 'test_alter', 'fruit'); +reset ($fruits); +array_walk ($fruits, 'test_print'); + </programlisting> + </example> + </para> + <simpara> + <function>each</function> ê·¸ë¦¬ê³ <function>list</function>를 ì°¸ê³ íë¼. + </simpara> + </refsect1> + </refentry> + <refentry id="function.arsort"> + <refnamediv> + <refname>arsort</refname> + <refpurpose> + ë°°ì´ì ììì¼ë¡ ì ë ¬íê³ ì¸ë±ì¤ì ìê´ê´ê³ë¥¼ ì ì§íë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>arsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ì´ í¨ìë ë°°ì´ì ì¸ë±ì¤ê° ê·¸ ë°°ì´ì ììì ìê´ê´ê³ë¥¼ ì ì§í´ì¼ íë + ë°°ì´ì ììì¼ë¡ ì ë ¬íë¤. ì´ í¨ìë ì£¼ë¡ ì¤ì ììì ì ë ¬ì´ ì¤ìí + ìê´ë°°ì´ì ì ë ¬í ê²½ì° ì´ì©ëë¤. + <example> + <title> + <function>Arsort</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +arsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key = $val\n"; +} + </programlisting> + </example> + </para> + <para> + ì´ ìë ë¤ìì ì¶ë ¥í ê²ì´ë¤: + </para> + <para> + <informalexample> + <programlisting> +fruits[a] = orange +fruits[d] = lemon +fruits[b] = banana +fruits[c] = apple + </programlisting> + </informalexample> + </para> + <para> + fruits ê° ìíë²³ ë°ëììë¡ ì ë ¬ëê³ , ê°ê°ì ììì ìê´ëë ì¸ë±ì¤ë + ì ì§ëìë¤. + </para> + <para> + ìµì 매ê°ë³ì <parameter>sort_flags</parameter>ë¡ ì ë ¬ë°©ë²ì + ìì í ì ìì¼ë©°, ìì¸í ì ë³´ë <function>sort</function>를 참조íë¼. + </para> + <para> + <function>asort</function>, <function>rsort</function>, + <function>ksort</function>, ê·¸ë¦¬ê³ <function>sort</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.asort"> + <refnamediv> + <refname>asort</refname> + <refpurpose>ë°°ì´ì ì ë ¬íê³ index associationì ì ì§íë¤. </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>asort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ì´ í¨ìë ë°°ì´ì ì¸ë±ì¤ê° ê·¸ ë°°ì´ì ììì ìê´ê´ê³ë¥¼ ì ì§í´ì¼ íë + ë°°ì´ì ì ë ¬íë¤. ì´ í¨ìë ì£¼ë¡ ì¤ì ììì ì ë ¬ì´ ì¤ìí + ìê´ë°°ì´ì ì ë ¬í ê²½ì° ì´ì©ëë¤. + <example> + <title> + <function>Asort</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +asort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key = $val\n"; +} + </programlisting> + </example> + </para> + <para> + ì´ ìì ì ê²°ê³¼ë ë¤ìê³¼ ê°ë¤: + </para> + <para> + <informalexample> + <programlisting> +fruits[c] = apple +fruits[b] = banana +fruits[d] = lemon +fruits[a] = orange + </programlisting> + </informalexample> + </para> + <para> + + fruits ê° ìíë²³ ììë¡ ì ë ¬ëê³ , ê°ê°ì ììì ìê´ëë ì¸ë±ì¤ë + ì ì§ëìë¤. + </para> + <para> + ìµì 매ê°ë³ì <parameter>sort_flags</parameter>ë¡ ì ë ¬ë°©ë²ì + ìì í ì ìì¼ë©°, ìì¸í ì ë³´ë <function>sort</function>를 참조íë¼. + </para> + <para> + <function>arsort</function>, <function>rsort</function>, + <function>ksort</function>, ê·¸ë¦¬ê³ <function>sort</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.compact"> + <refnamediv> + <refname>compact</refname> + <refpurpose> + 주ì´ì§ ì¬ë¬ ë³ìì ì´ë¦ê³¼ ê°ì ê°ì§ë ë°°ì´ì ë§ë ë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>compact</function> + </funcdef> + <paramdef>mixed <parameter>varname</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Compact</function> ë ë¤ìí ìì 매ê°ë³ì를 ê°ëë¤. + ê°ê° 매ê°ë³ìë ë³ìì ì´ë¦ì í¬í¨íë 문ìì´ì´ ë ìë ìê³ , + ë³ì ì´ë¦ì ë°°ì´ì´ ë ìë ìë¤. + ë°°ì´ì ê·¸ ìì ë³ì ì´ë¦ì ë°°ì´ì í¬í¨í ì ë ìë¤. + <function>compact</function> ë ì´ ë§¤ê°ë³ì를 ì¬ê·ì ì¼ë¡ ë¤ë£¬ë¤. + </para> + <para> + ì´ë° ê°ê°ì ê²½ì°ì, <function>compact</function> ë + 기존 ì¬ë³¼ í ì´ë¸ìì ê·¸ ì´ë¦ì í´ë¹íë ë³ì를 ì°¾ì ì¶ë ¥íë ë°°ì´ì + ì¶ê°í´ì, ë³ì ëª ì´ í¤ê° ëê³ ë³ìì ë´ì©ì´ ê·¸ í¤ì ê°ì´ ëë ë°°ì´ì + ë°ííë¤. + ê°ë¨í ë§í´, <function>extract</function>ì ë°ë ì´ë¤. + ì´ í¨ìë ì¶ê°ë 모ë ë³ì를 ê°ì§ë ë°°ì´ì ë°ííë¤. + </para> + <para> + ì§ì ëì§ ìì 문ìì´ì ë¨ìí ê°ê³¼ëë¤. + </para> + <para> + <example> + <title> + <function>Compact</function> ì</title> + <programlisting role="php"> +$city = "San Francisco"; +$state = "CA"; +$event = "SIGGRAPH"; + +$location_vars = array ("city", "state"); + +$result = compact ("event", "nothing_here", $location_vars); + </programlisting> + <para> + ì½ë ì¤í í, <varname>$result</varname> ë <literal>array ("event" + => "SIGGRAPH", "city" => "San Francisco", "state" => "CA")</literal>ì´ ë ê²ì´ë¤. + </para> + </example> + </para> + <para> + <function>extract</function> 를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.count"> + <refnamediv> + <refname>count</refname> + <refpurpose>ë°°ì´ ë³ìì ìì ê°ì를 구íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>count</function> + </funcdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ë°°ì´ <parameter>var</parameter>ì ììì ê°¯ì를 ë°ííëë°, + <parameter>var</parameter>ë ëê² ë°°ì´ì´ë¤.(ìëíë©´, ê·¸ ìì ë¤ë¥¸ê²ì + íëì í¸ë§ ê°ì§ ê²ì´ê¸° ë문ì´ë¤.) + </para> + <para> + ë°°ì´ì´ ìë ë³ìë¼ë©´ 1ì ë°ííë¤. + </para> + <para> + ë³ìê° ì ì¸ ëì§ ììë¤ë©´ 0ì ë°ííë¤. + <warning> + <para> + <function>Count</function> ë ì ì¸ëì§ ìì ë³ìì ëí´ 0ì ë°ííê² ì§ë§, + ììê° ìë ë°°ì´ë¡ ì´ê¸°íë ë³ìë 0ì ë°ííë¤. + ë³ìê° ì ì¸ëìëì§ë¥¼ ì기 ìí´ <function>isset</function>를 ì¬ì©íë¼. + </para> + </warning> + </para> + <para> + <example> + <title> + <function>Count</function> ì</title> + <programlisting role="php"> +$a[0] = 1; +$a[1] = 3; +$a[2] = 5; +$result = count ($a); +//$result ë 2ê° ìë 3ì´ë¤. ìëíë©´, 3ê°ì í ë¹ë ììê° ì기 ë문ì´ë¤. + +$a[2] = 1; +$a[4] = ""; +$a[6] = 5; +$a[8] = 7; +$a[10] = 11; +$a[12] = ""; +$result = count ($a); +// 4ê°ì í ë¹ë ììê° ìì¼ë¯ë¡ $result ì ê°ì 4 ì´ë¤. + </programlisting> + </example> + </para> + <para> + <function>sizeof</function>, + <function>isset</function>, ê·¸ë¦¬ê³ + <function>is_array</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.current"> + <refnamediv> + <refname>current</refname> + <refpurpose>ë°°ì´ì íì¬ ìì를 ëë ¤ì¤ë¤</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>current</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ê°ê°ì ë°°ì´ì íì¬ ìì를 ê°ë¦¬í¤ë ë´ë¶í¬ì¸í°ë¥¼ ê°ëë°, + ì´ ë´ë¶ í¬ì¸í°ë ë°°ì´ì ì½ì ëì´ì§ 첫ë²ì§¸ ìììì ì´ê¸°íëë¤. + </para> + <para> + <function>current</function> í¨ìë ë¨ìí ë´ë¶ í¬ì¸í°ì ìí´ + ì§ìëë íì¬ì ìì를 ë°ííë¤. + ì´ í¨ìë í¬ì¸í°ë¥¼ ì´ë í ë°©ë²ì¼ë¡ë ì´ëìí¤ì§ ìëë¤. + ë´ë¶ í¬ì¸í°ê° ìì 목ë¡ì ë²ì를 ëì´ì ê³³ì ì§ìíë©´, + <function>current</function> ë ê±°ì§(false)를 ë°ííë¤. + <warning> + <para> + ë°°ì´ì´ ê°ì§ë ììê° íëë ìë¤ë©´ (0 ì´ê±°ë "", ë¹ë¬¸ìì´) + ì´ í¨ìë ì´ ììë¤ì ëí´ìë ê±°ì§(false)를 ë°ííë¤. + ì´ë문ì ì§ê¸ ì¬ì©ì¤ì¸ <function>current</function> ë°°ì´ìì + ì ë§ ë¦¬ì¤í¸ì ëì ìëì§ ìëë©´ ë¹ ë°°ì´ì¸ì§ë¥¼ 구ë¶í기 ì´ë µë¤. + ë°°ì´ì´ ììê° ìë ë¹ ë°°ì´ì¸ì§ë¥¼ ìë§ê² ê²í í기 ìí´ìë + <function>each</function> í¨ì를 ì¬ì©íë¼. + </para> + </warning> + </para> + <para> + <function>end</function>, <function>next</function>, + <function>prev</function>, ê·¸ë¦¬ê³ <function>reset</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.each"> + <refnamediv> + <refname>each</refname> + <refpurpose> + ë°°ì´ë¡ë¶í° ë¤ìììì í¤ì ê° ìì ë°ííë¤. + Return the next key and value pair from an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>each</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <parameter>array</parameter> ë°°ì´ìì ë¤ì key/value ìì ë°ííë¤. + ì´ ìì ë¤ ê°ì ìì를 ê°ì§ ë°°ì´ë¡ ë°íëëë° ì´ ë¤ ê°ì ììì keyë + <emphasis>0</emphasis>, <emphasis>1</emphasis>, + <emphasis>key</emphasis>, ê·¸ë¦¬ê³ <emphasis>value</emphasis> + ì´ë¤. + <emphasis>0</emphasis> ê³¼ <emphasis>key</emphasis> + ììë ê°ê° ë³ìì key ì´ë¦ì ê°ì§ê³ , + <emphasis>1</emphasis> ê³¼ <emphasis>value</emphasis>ë + ê·¸ ê°ì ê°ì§ê³ ìë¤. + </para> + <para> + ë§ì½ ê·¸ ë°°ì´ì í´ë¹íë ë´ë¶ í¬ì¸í°ê° ë°°ì´ì ë²ì를 ì§ëë©´, + <function>each</function>ë ê±°ì§(false)를 ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Each</function> ì</title> + <programlisting role="php"> +$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese"); +$bar = each ($foo); + </programlisting> + <para> + <varname>$bar</varname> ë ë¤ìì í¤(key)/ê°(value) ìì ê°ëë¤. + pairs: + <itemizedlist spacing="compact"> + <listitem> + <simpara>0 => 0</simpara> + </listitem> + <listitem> + <simpara>1 => 'bob'</simpara> + </listitem> + <listitem> + <simpara>key => 0</simpara> + </listitem> + <listitem> + <simpara>value => 'bob'</simpara> + </listitem> + </itemizedlist> + <programlisting role="php"> +$foo = array ("Robert" => "Bob", "Seppo" => "Sepi"); +$bar = each ($foo); + </programlisting> + </para> + <para> + <varname>$bar</varname> ë ë¤ìì í¤(key)/ê°(value) ìì ê°ëë¤. + <itemizedlist spacing="compact"> + <listitem> + <simpara>0 => 'Robert'</simpara> + </listitem> + <listitem> + <simpara>1 => 'Bob'</simpara> + </listitem> + <listitem> + <simpara>key => 'Robert'</simpara> + </listitem> + <listitem> + <simpara>value => 'Bob'</simpara> + </listitem> + </itemizedlist> + </para> + </example> + </para> + <para> + <function>Each</function> ë ëì²´ë¡ ë°°ì´ì ê²í í기 ìí´ + <function>list</function> ì í¨ê» ì°ì¸ë¤; ì를 ë¤ë©´ + <varname>$HTTP_POST_VARS</varname>: + <example> + <title> + Traversing <varname>$HTTP_POST_VARS</varname> with + <function>each</function> + </title> + <programlisting role="php"> +echo "Values submitted via POST method:<br>"; +reset ($HTTP_POST_VARS); +while (list ($key, $val) = each ($HTTP_POST_VARS)) { + echo "$key => $val<br>"; +} + </programlisting> + </example> + </para> + <para> + After <function>each</function> has executed, the array cursor + will be left on the next element of the array, or on the last + element if it hits the end of the array. + </para> + <para> + See also <function>key</function>, <function>list</function>, + <function>current</function>, <function>reset</function>, + <function>next</function>, and <function>prev</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.end"> + <refnamediv> + <refname>end</refname> + <refpurpose> + Set the internal pointer of an array to its last element + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>end</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>End</function> advances <parameter>array</parameter>'s + internal pointer to the last element, and returns that element. + </para> + <para> + See also: <function>current</function>, + <function>each</function>, <function>end</function>, + <function>next</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.extract"> + <refnamediv> + <refname>extract</refname> + <refpurpose> + Import variables into the symbol table from an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>extract</function> + </funcdef> + <paramdef>array <parameter>var_array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>extract_type</optional> + </parameter> + </paramdef> + <paramdef>string + <parameter> + <optional>prefix</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function is used to import variables from an array into the + current symbol table. It takes associative array + <parameter>var_array</parameter> and treats keys as variable + names and values as variable values. For each key/value pair it + will create a variable in the current symbol table, subject to + <parameter>extract_type</parameter> and + <parameter>prefix</parameter> parameters. + </para> + <para> + <function>Extract</function> checks for colissions with existing + variables. The way collisions are treated is determined by + <parameter>extract_type</parameter>. It can be one of the + following values: + <variablelist> + <varlistentry> + <term>EXTR_OVERWRITE</term> + <listitem> + <simpara> + If there is a collision, overwrite the existing variable. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_SKIP</term> + <listitem> + <simpara> + If there is a collision, don't overwrite the existing + variable. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_PREFIX_SAME</term> + <listitem> + <simpara>If there is a collision, prefix the new variable with + <parameter>prefix</parameter>. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_PREFIX_ALL</term> + <listitem> + <simpara> + Prefix all variables with <parameter>prefix</parameter>. + </simpara> + </listitem> + </varlistentry> + </variablelist> + </para> + <para> + If <parameter>extract_type</parameter> is not specified, it is + assumed to be EXTR_OVERWRITE. + </para> + <para> + Note that <parameter>prefix</parameter> is only required if + <parameter>extract_type</parameter> is EXTR_PREFIX_SAME or + EXTR_PREFIX_ALL. + </para> + <para> + <function>Extract</function> checks each key to see if it + constitues a valid variable name, and if it does only then does + it proceed to import it. + </para> + <para> + A possible use for extract is to import into symbol table + variables contained in an associative array returned by + <function>wddx_deserialize</function>. + </para> + <para> + <example> + <title> + <function>Extract</function> example</title> + <programlisting role="php"> +<?php + +/* Suppose that $var_array is an array returned from + wddx_deserialize */ + +$size = "large"; +$var_array = array ("color" => "blue", + "size" => "medium", + "shape" => "sphere"); +extract ($var_array, EXTR_PREFIX_SAME, "wddx"); + +print "$color, $size, $shape, $wddx_size\n"; + +?> + </programlisting> + </example> + </para> + <para> + The above example will produce: + <programlisting> +blue, large, sphere, medium + </programlisting> + </para> + <para> + The <varname>$size</varname> wasn't overwritten, becaus we + specified EXTR_PREFIX_SAME, which resulted in + <varname>$wddx_size</varname> being created. If EXTR_SKIP was + specified, then $wddx_size wouldn't even have been created. + EXTR_OVERWRITE would have cause <varname>$size</varname> to have + value "medium", and EXTR_PREFIX_ALL would result in new variables + being named <varname>$wddx_color</varname>, + <varname>$wddx_size</varname>, and + <varname>$wddx_shape</varname>. + </para> + <para> + You must use an associative array, a numerically indexed array + will not produce results. + </para> + <para> + See also: <function>compact</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.in-array"> + <refnamediv> + <refname>in_array</refname> + <refpurpose>Return true if a value exists in an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>bool in_array</funcdef> + <paramdef>mixed <parameter>needle</parameter> + </paramdef> + <paramdef>array <parameter>haystack</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Searches <parameter>haystack</parameter> for + <parameter>needle</parameter> and returns true if it is found in + the array, false otherwise. + </para> + <para> + <example> + <title> + <function>In_array</function> example</title> + <programlisting role="php"> +$os = array ("Mac", "NT", "Irix", "Linux"); +if (in_array ("Irix", $os)){ + print "Got Irix"; + } + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.key"> + <refnamediv> + <refname>key</refname> + <refpurpose>Fetch a key from an associative array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>key</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Key</function> returns the index element of the + current array position. + </para> + <para> + See also <function>current</function> and <function>next</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.krsort"> + <refnamediv> + <refname>krsort</refname> + <refpurpose>Sort an array by key in reverse order</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>krsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Sorts an array by key in reverse order, maintaining key to data + correlations. This is useful mainly for associative arrays. + <example> + <title> + <function>Krsort</function> example</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +krsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[d] = lemon +fruits[c] = apple +fruits[b] = banana +fruits[a] = orange + </programlisting> + </informalexample> + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <simpara> + See also <function>asort</function>, <function>arsort</function>, + <function>ksort</function> + <function>sort</function>, + <function>natsort</function>and <function>rsort</function>. + </simpara> + </refsect1> + </refentry> + <refentry id="function.ksort"> + <refnamediv> + <refname>ksort</refname> + <refpurpose>Sort an array by key</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>ksort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Sorts an array by key, maintaining key to data correlations. This + is useful mainly for associative arrays. + <example> + <title> + <function>Ksort</function> example</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +ksort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[a] = orange +fruits[b] = banana +fruits[c] = apple +fruits[d] = lemon + </programlisting> + </informalexample> + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <simpara> + See also <function>asort</function>, <function>arsort</function>, + <function>sort</function>, <function>natsort</function>, and + <function>rsort</function>. + </simpara> + <note> + <para> + The second parameter was added in PHP 4. + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.list"> + <refnamediv> + <refname>list</refname> + <refpurpose> + Assign variables as if they were an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>list</function> + </funcdef> + <varargs/> + </funcprototype> + </funcsynopsis> + <para> + Like <function>array</function>, this is not really a function, + but a language construct. <function>list</function> is used to + assign a list of variables in one operation. + <example> + <title> + <function>List</function> example</title> + <programlisting role="php"> +<table> + <tr> + <th>Employee name</th> + <th>Salary</th> + </tr> + +<?php + +$result = mysql ($conn, "SELECT id, name, salary FROM employees"); +while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { + print (" <tr>\n". + " <td><a href=\"info.php3?id=$id\">$name</a></td>\n". + " <td>$salary</td>\n". + " </tr>\n"); +} + +?> + +</table> + </programlisting> + </example> + </para> + <para> + See also <function>each</function> and <function>array</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.natsort"> + <refnamediv> + <refname>natsort</refname> + <refpurpose> + Sort an array using a "natural order" algorithm + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>natsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function implements a sort algorithm that orders + alphanumeric strings in the way a human being would. This is + described as a "natural ordering". An example of the difference + between this algorithm and the regular computer string sorting + algorithms (used in <function>sort</function>) can be seen below: + </para> + <para> + <example> + <title> + <function>natsort</function> example</title> + <programlisting role="php"> +$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); + +sort($array1); +echo "Standard sorting\n"; +print_r($array1); + +natsort($array2); +echo "\nNatural order sorting\n"; +print_r($array2); + </programlisting> + </example> + </para> + <para> + The code above will generate the following output: + </para> + <para> + <informalexample> + <programlisting> +Standard sorting +Array +( + [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 +) + </programlisting> + </informalexample> + For more infomation see: Martin Pool's <ulink url="&url.strnatcmp;">Natural Order String Comparison</ulink> + page. + </para> + <para> + See also <function>natcasesort</function>, + <function>strnatcmp</function> and + <function>strnatcasecmp</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.natcasesort"> + <refnamediv> + <refname>natcasesort</refname> + <refpurpose> + Sort an array using a case insensitive "natural order" algorithm + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>natcasesort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function implements a sort algorithm that orders + alphanumeric strings in the way a human being would. This is + described as a "natural ordering". + </para> + <para> + <function>natcasesort</function> is a case insensitive version of + <function>natsort</function>. See <function>natsort</function> + for an example of the difference between this algorithm and the + regular computer string sorting algorithms. + </para> + <para> + For more infomation see: Martin Pool's <ulink url="&url.strnatcmp;">Natural Order String Comparison</ulink> + page. + </para> + <para> + See also <function>sort</function>, + <function>natsort</function>, + <function>strnatcmp</function> and + <function>strnatcasecmp</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.next"> + <refnamediv> + <refname>next</refname> + <refpurpose> + Advance the internal array pointer of an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>next</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the array element in the next place that's pointed by the + internal array pointer, or false if there are no more elements. + </para> + <para> + <function>Next</function> behaves like + <function>current</function>, with one difference. It advances + the internal array pointer one place forward before returning the + 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, <function>next</function> returns false. + <warning> + <para> + 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 + <function>each</function> function. + </para> + </warning> + </para> + <para> + See also: + <function>current</function>, <function>end</function>, + <function>prev</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.pos"> + <refnamediv> + <refname>pos</refname> + <refpurpose>Get the current element from an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>pos</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <simpara> + This is an alias for <function>current</function>. + </simpara> + <para> + See also: + <function>end</function>, <function>next</function>, + <function>prev</function> and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.prev"> + <refnamediv> + <refname>prev</refname> + <refpurpose>Rewind the internal array pointer</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>prev</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the array element in the previous place that's pointed by + the internal array pointer, or false if there are no more + elements. + <warning> + <para> + 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 + <function>each</function> function. + </para> + </warning> + </para> + <para> + <function>Prev</function> behaves just like + <function>next</function>, except it rewinds the internal array + pointer one place instead of advancing it. + </para> + <para> + See also: <function>current</function>, <function>end</function>, + <function>next</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.range"> + <refnamediv> + <refname>range</refname> + <refpurpose> + Create an array containing a range of integers + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>range</function> + </funcdef> + <paramdef>int <parameter>low</parameter> + </paramdef> + <paramdef>int <parameter>high</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Range</function> returns an array of integers from + <parameter>low</parameter> to <parameter>high</parameter>, + inclusive. + </para> + <para> + See <function>shuffle</function> for an example of its use. + </para> + </refsect1> + </refentry> + <refentry id="function.reset"> + <refnamediv> + <refname>reset</refname> + <refpurpose> + Set the internal pointer of an array to its first element + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>reset</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Reset</function> rewinds <parameter>array</parameter>'s + internal pointer to the first element. + </para> + <para> + <function>Reset</function> returns the value of the first array + element. + </para> + <para> + See also: <function>current</function>, + <function>each</function>, <function>next</function>, + and <function>prev</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.rsort"> + <refnamediv> + <refname>rsort</refname> + <refpurpose>Sort an array in reverse order</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>rsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array in reverse order (highest to lowest). + <example> + <title> + <function>Rsort</function> example</title> + <programlisting role="php"> +$fruits = array ("lemon", "orange", "banana", "apple"); +rsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[0] = orange +fruits[1] = lemon +fruits[2] = banana +fruits[3] = apple + </programlisting> + </informalexample> + </para> + <para> + The fruits have been sorted in reverse alphabetical order. + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <para> + See also: <function>arsort</function>, + <function>asort</function>, <function>ksort</function>, + <function>sort</function>, and <function>usort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.shuffle"> + <refnamediv> + <refname>shuffle</refname> + <refpurpose>Shuffle an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>shuffle</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function shuffles (randomizes the order of the elements in) + an array. You must use <function>srand</function> to seed this + function. + <example> + <title> + <function>Shuffle</function> example</title> + <programlisting role="php"> +$numbers = range (1,20); +srand ((double)microtime()*1000000); +shuffle ($numbers); +while (list (, $number) = each ($numbers)) { + echo "$number "; +} + </programlisting> + </example> + </para> + <para> + See also <function>arsort</function>, <function>asort</function>, + <function>ksort</function>, <function>rsort</function>, + <function>sort</function> and <function>usort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.sizeof"> + <refnamediv> + <refname>sizeof</refname> + <refpurpose>Get the number of elements in an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>sizeof</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the number of elements in the array. + </para> + <para> + See also <function>count</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.sort"> + <refnamediv> + <refname>sort</refname> + <refpurpose>Sort an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>sort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array. Elements will be arranged from + lowest to highest when this function has completed. + <example> + <title> + <function>Sort</function> example</title> + <programlisting role="php"> +<?php + +$fruits = array ("lemon", "orange", "banana", "apple"); +sort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "fruits[".$key."] = ".$val; +} + +?> + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[0] = apple +fruits[1] = banana +fruits[2] = lemon +fruits[3] = orange + </programlisting> + </informalexample> + </para> + <para> + The fruits have been sorted in alphabetical order. + </para> + <para> + The optional second parameter <parameter>sort_flags</parameter> + may be used to modify the sorting behavior using theese valies: + </para> + <para> + Sorting type flags: + <itemizedlist> + <listitem> + <simpara>SORT_REGULAR - compare items normally</simpara> + </listitem> + <listitem> + <simpara>SORT_NUMERIC - compare items numerically</simpara> + </listitem> + <listitem> + <simpara>SORT_STRING - compare items as strings</simpara> + </listitem> + </itemizedlist> + </para> + <para> + See also: <function>arsort</function>, + <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>. + </para> + <note> + <para> + The second parameter was added in PHP 4. + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.uasort"> + <refnamediv> + <refname>uasort</refname> + <refpurpose> + Sort an array with a user-defined comparison function and + maintain index association + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>uasort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>function <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array such that array indices maintain + their correlation with the array elements they are associated + with. This is used mainly when sorting associative arrays where + the actual element order is significant. The comparison function + is user-defined. + </para> + <note> + <para> + Please see <function>usort</function> and + <function>uksort</function> for examples of user-defined + comparison functions. + </para> + </note> + <para> + See also: <function>usort</function>, <function>uksort</function>, + <function>sort</function>, <function>asort</function>, + <function>arsort</function>, <function>ksort</function> + and <function>rsort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.uksort"> + <refnamediv> + <refname>uksort</refname> + <refpurpose> + Sort an array by keys using a user-defined comparison function + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>uksort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>function <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function will sort the keys of an array using a + user-supplied comparison function. If the array you wish to sort + needs to be sorted by some non-trivial criteria, you should use + this function. + </para> + <para> + <example> + <title> + <function>Uksort</function> example</title> + <programlisting role="php"> +function cmp ($a, $b) { + if ($a == $b) return 0; + return ($a > $b) ? -1 : 1; +} + +$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); + +uksort ($a, "cmp"); + +while (list ($key, $value) = each ($a)) { + echo "$key: $value\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +20: twenty +10: ten +4: four +3: three + </programlisting> + </informalexample> + </para> + <para> + See also: <function>usort</function>, <function>uasort</function>, + <function>sort</function>, <function>asort</function>, + <function>arsort</function>, <function>ksort</function>, + <function>natsort</function> and <function>rsort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.usort"> + <refnamediv> + <refname>usort</refname> + <refpurpose> + Sort an array by values using a user-defined comparison function + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>usort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>string <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function will sort an array by its values using a + user-supplied comparison function. If the array you wish to sort + needs to be sorted by some non-trivial criteria, you should use + this function. + </para> + <para> + The comparison function must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. If two members compare as equal, their order in the + sorted array is undefined. + </para> + <para> + <example> + <title> + <function>Usort</function> example</title> + <programlisting role="php"> +function cmp ($a, $b) { + if ($a == $b) return 0; + return ($a > $b) ? -1 : 1; +} + +$a = array (3, 2, 5, 6, 1); + +usort ($a, "cmp"); + +while (list ($key, $value) = each ($a)) { + echo "$key: $value\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +0: 6 +1: 5 +2: 3 +3: 2 +4: 1 + </programlisting> + </informalexample> + </para> + <note> + <para> + Obviously in this trivial case the <function>rsort</function> + function would be more appropriate. + </para> + </note> + <para> + <example> + <title> + <function>Usort</function> example using multi-dimensional array + </title> + <programlisting role="php"> +function cmp ($a, $b) { + return strcmp($a["fruit"],$b["fruit"]); +} + +$fruits[0]["fruit"] = "lemons"; +$fruits[1]["fruit"] = "apples"; +$fruits[2]["fruit"] = "grapes"; + +usort($fruits, "cmp"); + +while (list ($key, $value) = each ($fruits)) { + echo "\$fruits[$key]: " . $value["fruit"] . "\n"; +} + </programlisting> + </example> + </para> + <para> + When sorting a multi-dimensional array, $a and $b contain + references to the first index of the array. + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +$fruits[0]: apples +$fruits[1]: grapes +$fruits[2]: lemons + </programlisting> + </informalexample> + </para> + <para> + <warning> + <para> + The underlying quicksort function in some C libraries (such as + on Solaris systems) may cause PHP to crash if the comparison + function does not return consistent values. + </para> + </warning> + </para> + <para> + 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> + </refsect1> + </refentry> +</reference> +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:1 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:"../../manual.ced" +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +-->
Index: phpdoc/kr/functions/array.xml diff -u phpdoc/kr/functions/array.xml:1.3 phpdoc/kr/functions/array.xml:1.4 --- phpdoc/kr/functions/array.xml:1.3 Wed Feb 28 04:07:42 2001 +++ phpdoc/kr/functions/array.xml Fri Mar 2 00:41:53 2001 @@ -1,2780 +1,2795 @@ - <reference id="ref.array"> - <title>Array Functions</title> - <titleabbrev>Arrays</titleabbrev> - <partintro> - <simpara> - These functions allow you to interact with and manipulate - arrays in various ways. Arrays are essential for storing, - managing, and operating on sets of variables. - </simpara> - <simpara> - Simple and multi-dimensional arrays are supported, and may be - either user created or created by another function. - There are specific database handling functions for populating - arrays from database queries, and several functions return arrays. - </simpara> - <para> - See also <function>is_array</function>, <function>explode</function>, - <function>implode</function>, <function>split</function> - and <function>join</function>. - </para> - </partintro> - - <refentry id="function.array"> - <refnamediv> - <refname>array</refname> - <refpurpose> - Create an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array</function></funcdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns an array of the parameters. The parameters can be given - an index with the <literal>=></literal> operator. - </para> - <para> - <note> - <para> - <function>Array</function> is a language construct used to - represent literal arrays, and not a regular function. - </para> - </note> - </para> - <para> - 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. - </para> - <para> - 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 - arrays. - <example> - <title><function>Array</function> example</title> - <programlisting role="php"> -$fruits = array ( - "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"), - "numbers" => array (1, 2, 3, 4, 5, 6), - "holes" => array ("first", 5 => "second", "third") -); - </programlisting> - </example> - </para> - <para> - <example> - <title>Automatic index with <function>Array</function></title> - <programlisting role="php"> -$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); -print_r($array); - </programlisting> - </example> - which will display : - <informalexample> - <programlisting> -Array -( - [0] => 1 - [1] => 1 - [2] => 1 - [3] => 13 - [4] => 1 - [8] => 1 - [9] => 19 -) - </programlisting> - </informalexample> - 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. - </para> - <para> - This example creates a 1-based array. - <example> - <title>1-based index with <function>Array</function></title> - <programlisting role="php"> - $firstquarter = array(1 => 'January', 'February', 'March'); - print_r($firstquarter); - </programlisting> - </example> - which will display : - <informalexample> - <programlisting> -Array -( - [1] => 'January' - [2] => 'February' - [3] => 'March' -) - </programlisting> - </informalexample> - </para> - <para> - See also: <function>list</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-count-values"> - <refnamediv> - <refname>array_count_values</refname> - <refpurpose>Counts all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_count_values</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_count_values</function> returns an array using - the values of the <parameter>input</parameter> array as keys and - their frequency in <parameter>input</parameter> as values. - </para> - <para> - <example> - <title><function>Array_count_values</function> example</title> - <programlisting role="php"> -$array = array (1, "hello", 1, "world", "hello"); -array_count_values ($array); // returns array (1=>2, "hello"=>2, "world"=>1) - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-diff"> - <refnamediv> - <refname>array_diff</refname> - <refpurpose>Computes the difference of arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_diff</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional> ...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_diff</function> returns an array - containing all the values of <parameter>array1</parameter> - that are not present in any of the other arguments. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_diff</function> example</title> - <programlisting role="php"> -$array1 = array ("a" => "green", "red", "blue"); -$array2 = array ("b" => "green", "yellow", "red"); -$result = array_diff ($array1, $array2); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array - ("blue");</literal> - </para> - <para> - See also <function>array_intersect</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-flip"> - <refnamediv> - <refname>array_flip</refname> - <refpurpose>Flip all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_flip</function></funcdef> - <paramdef>array <parameter>trans</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_flip</function> returns an array in flip order. - </para> - <para> - <example> - <title><function>Array_flip</function> example</title> - <programlisting role="php"> -$trans = array_flip ($trans); -$original = strtr ($str, $trans); - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-intersect"> - <refnamediv> - <refname>array_intersect</refname> - <refpurpose>Computes the intersection of arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_intersect</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional> ...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_intersect</function> returns an array - containing all the values of <parameter>array1</parameter> - that are present in all the arguments. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_intersect</function> example</title> - <programlisting role="php"> -$array1 = array ("a" => "green", "red", "blue"); -$array2 = array ("b" => "green", "yellow", "red"); -$result = array_intersect ($array1, $array2); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array ("a" - => "green", "red");</literal> - </para> - <para> - See also <function>array_diff</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-keys"> - <refnamediv> - <refname>array_keys</refname> - <refpurpose>Return all the keys of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_keys</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>mixed - <parameter> - <optional>search_value</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_keys</function> returns the keys, numeric and - string, from the <parameter>input</parameter> array. - </para> - <para> - If the optional <parameter>search_value</parameter> is specified, - then only the keys for that value are returned. Otherwise, all - the keys from the <parameter>input</parameter> are returned. - </para> - <para> - <example> - <title><function>Array_keys</function> example</title> - <programlisting role="php"> -$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") - </programlisting> - </example> - </para> - <note> - <para> - This function was added to PHP 4, below is an implementation for - those still using PHP 3. - <example> - <title> - 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) - continue; - $t[] = $k; - } - return $t; -} - </programlisting> - </example> - </para> - </note> - <para> - See also <function>array_values</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-merge"> - <refnamediv> - <refname>array_merge</refname> - <refpurpose>Merge two or more arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_merge</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_merge</function> merges the elements of two or - more arrays together so that the values of one are appended to - the end of the previous one. It returns the resulting array. - </para> - <para> - If the input arrays have the same string keys, then the later - value for that key will overwrite the previous one. If, however, - the arrays have the same numeric key, the later value will not - overwrite the original value, but will be appended. - </para> - <para> - <example> - <title><function>array_merge</function> example</title> - <programlisting role="php"> -$array1 = array ("color" => "red", 2, 4); -$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4); -array_merge ($array1, $array2); - </programlisting> - </example> - </para> - <para> - Resulting array will be <literal>array("color" => "green", 2, 4, - "a", "b", "shape" => "trapezoid", 4)</literal>. - </para> - <para> - See also <function>array_merge_recursive</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-merge-recursive"> - <refnamediv> - <refname>array_merge_recursive</refname> - <refpurpose>Merge two or more arrays recursively</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_merge_recursive</function></funcdef> - <paramdef>array <parameter>array1</parameter></paramdef> - <paramdef>array <parameter>array2</parameter></paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_merge_recursive</function> merges the elements of - two or more arrays together so that the values of one are appended - to the end of the previous one. It returns the resulting array. - </para> - <para> - If the input arrays have the same string keys, then the values for - these keys are merged together into an array, and this is done - recursively, so that if one of the values is an array itself, the - function will merge it with a corresponding entry in another array - too. If, however, the arrays have the same numeric key, the later - value will not overwrite the original value, but will be appended. - </para> - <para> - <example> - <title><function>Array_merge_recursive</function> example</title> - <programlisting role="php"> -$ar1 = array ("color" => array ("favorite" => "red"), 5); -$ar2 = array (10, "color" => array ("favorite" => "green", "blue")); -$result = array_merge_recursive ($ar1, $ar2); - </programlisting> - </example> - </para> - <para> - Resulting array will be <literal>array ("color" => array - ("favorite" => array ("red", "green"), "blue"), 5, 10)</literal>. - </para> - <para> - See also <function>array_merge</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-multisort"> - <refnamediv> - <refname>array_multisort</refname> - <refpurpose>Sort multiple or multi-dimensional arrays</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>bool <function>array_multisort</function></funcdef> - <paramdef>array <parameter>ar1</parameter></paramdef> - <paramdef>mixed - <parameter><optional>arg</optional></parameter> - </paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - <paramdef>array - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_multisort</function> can be used to sort several - arrays at once or a multi-dimensional array according by one of - more dimensions. It maintains key association when sorting. - </para> - <para> - The input arrays are treated as columns of a table to be sorted - by rows - this resembles the functionality of SQL ORDER BY - clause. The first array is the primary one to sort by. The rows - (values) in that array that compare the same are sorted by the - next input array, and so on. - </para> - <para> - The argument structure of this function is a bit unusual, but - flexible. The very first argument has to be an - array. Subsequently, each argument can be either an array or a - sorting flag from the following lists. - </para> - <para> - Sorting order flags: - <itemizedlist> - <listitem> - <simpara>SORT_ASC - sort in ascending order</simpara> - </listitem> - <listitem> - <simpara>SORT_DESC - sort in descending order</simpara> - </listitem> - </itemizedlist> - </para> - <para> - Sorting type flags: - <itemizedlist> - <listitem> - <simpara>SORT_REGULAR - compare items normally</simpara> - </listitem> - <listitem> - <simpara>SORT_NUMERIC - compare items numerically</simpara> - </listitem> - <listitem> - <simpara>SORT_STRING - compare items as strings</simpara> - </listitem> - </itemizedlist> - </para> - <para> - No two sorting flags of the same type can be specified after each - array. The sortings flags specified after an array argument apply - only to that array - they are reset to default SORT_ASC and - SORT_REGULAR after before each new array argument. - </para> - <para> - Returns <literal>TRUE</literal> on success, <literal>FALSE</literal> - on failure. - </para> - <para> - <example> - <title>Sorting multiple arrays</title> - <programlisting role="php"> -$ar1 = array ("10", 100, 100, "a"); -$ar2 = array (1, 3, "2", 1); -array_multisort ($ar1, $ar2); - </programlisting> - </example> - </para> - <para> - In this example, after sorting, the first array will contain 10, - "a", 100, 100. The second array will contain 1, 1, 2, "3". The - entries in the second array corresponding to the identical - entries in the first array (100 and 100) were sorted as well. - </para> - <para> - <example> - <title>Sorting multi-dimensional array</title> - <programlisting role="php"> -$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); -array_multisort ($ar[0], SORT_ASC, SORT_STRING, - $ar[1], SORT_NUMERIC, SORT_DESC); - </programlisting> - </example> - </para> - <para> - In this example, after sorting, the first array will contain 10, - 100, 100, "a" (it was sorted as strings in ascending order), and - the second one will contain 1, 3, "2", 1 (sorted as numbers, in - descending order). - </para> - </refsect1> - </refentry> - - <refentry id="function.array-pad"> - <refnamediv> - <refname>array_pad</refname> - <refpurpose> - Pad array to the specified length with a value - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_pad</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int <parameter>pad_size</parameter></paramdef> - <paramdef>mixed <parameter>pad_value</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_pad</function> returns a copy of the - <parameter>input</parameter> padded to size specified by - <parameter>pad_size</parameter> with value - <parameter>pad_value</parameter>. If - <parameter>pad_size</parameter> is positive then the array is - padded on the right, if it's negative then on the left. If the - absolute value of <parameter>pad_size</parameter> is less than or - equal to the length of the <parameter>input</parameter> then no - padding takes place. - </para> - <para> - <example> - <title><function>Array_pad</function> example</title> - <programlisting role="php"> -$input = array (12, 10, 9); - -$result = array_pad ($input, 5, 0); -// result is array (12, 10, 9, 0, 0) - -$result = array_pad ($input, -7, -1); -// result is array (-1, -1, -1, -1, 12, 10, 9) - -$result = array_pad ($input, 2, "noop"); -// not padded - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-pop"> - <refnamediv> - <refname>array_pop</refname> - <refpurpose>Pop the element off the end of array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_pop</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_pop</function> pops and returns the last value of - the <parameter>array</parameter>, shortening the - <parameter>array</parameter> by one element. - </para> - <para> - <example> - <title><function>Array_pop</function> example</title> - <programlisting role="php"> -$stack = array ("orange", "apple", "raspberry"); -$fruit = array_pop ($stack); - </programlisting> - </example> - </para> - <para> - After this, <varname>$stack</varname> has only 2 elements: - "orange" and "apple", and <varname>$fruit</varname> has - "raspberry". - </para> - <para> - See also <function>array_push</function>, - <function>array_shift</function>, and - <function>array_unshift</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-push"> - <refnamediv> - <refname>array_push</refname> - <refpurpose> - Push one or more elements onto the end of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_push</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_push</function> treats - <parameter>array</parameter> as a stack, and pushes the passed - variables onto the end of <parameter>array</parameter>. The - length of <parameter>array</parameter> increases by the number of - variables pushed. Has the same effect as: - <programlisting role="php"> -$array[] = $var; - </programlisting> - repeated for each <parameter>var</parameter>. - </para> - <para> - Returns the new number of elements in the array. - </para> - <para> - <example> - <title><function>Array_push</function> example</title> - <programlisting role="php"> -$stack = array (1, 2); -array_push ($stack, "+", 3); - </programlisting> - </example> - </para> - <para> - This example would result in <varname>$stack</varname> having 4 - elements: 1, 2, "+", and 3. - </para> - <para> - See also: <function>array_pop</function>, - <function>array_shift</function>, and - <function>array_unshift</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-rand"> - <refnamediv> - <refname>array_rand</refname> - <refpurpose> - Pick one or more random entries out of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_rand</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int - <parameter><optional>num_req</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_rand</function> is rather useful when you want to - pick one or more random entries out of an array. It takes an - <parameter>input</parameter> array and an optional argument - <parameter>num_req</parameter> which specifies how many entries you - want to pick - if not specified, it defaults to 1. - </para> - <para> - If you are picking only one entry, <function>array_rand</function> - returns the key for a random entry. Otherwise, it returns an array - of keys for the random entries. This is done so that you can pick - random keys as well as values out of the array. - </para> - <para> - Don't forget to call <function>srand</function> to seed the random - number generator. - </para> - <para> - <example> - <title><function>Array_rand</function> example</title> - <programlisting role="php"> -srand ((double) microtime() * 10000000); -$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); -$rand_keys = array_rand ($input, 2); -print $input[$rand_keys[0]]."\n"; -print $input[$rand_keys[1]]."\n"; - </programlisting> - </example> - </para> - </refsect1> - </refentry> - - <refentry id="function.array-reverse"> - <refnamediv> - <refname>array_reverse</refname> - <refpurpose> - Return an array with elements in reverse order - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_reverse</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>bool <parameter><optional>preserve_keys</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_reverse</function> takes input - <parameter>array</parameter> and returns a new array with the - order of the elements reversed, preserving the keys if - <parameter>preserve_keys</parameter> is <literal>TRUE</literal>. - </para> - <para> - <example> - <title><function>Array_reverse</function> example</title> - <programlisting role="php"> -$input = array ("php", 4.0, array ("green", "red")); -$result = array_reverse ($input); -$result_keyed = array_reverse ($input, TRUE); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array - (array ("green", "red"), 4.0, "php")</literal>. But - <varname>$result2[0]</varname> is still - <literal>"php"</literal>. - </para> - <note> - <para> - The second parameter was added in PHP 4.0.3. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.array-shift"> - <refnamediv> - <refname>array_shift</refname> - <refpurpose> - Pop an element off the beginning of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_shift</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <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. - </para> - <para> - <example> - <title><function>Array_shift</function> example</title> - <programlisting role="php"> -$args = array ("-v", "-f"); -$opt = array_shift ($args); - </programlisting> - </example> - </para> - <para> - This would result in <varname>$args</varname> having one element - "-f" left, and <varname>$opt</varname> being "-v". - </para> - <para> - See also <function>array_unshift</function>, - <function>array_push</function>, and - <function>array_pop</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-slice"> - <refnamediv> - <refname>array_slice</refname> - <refpurpose>Extract a slice of the array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_slice</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter>offset</parameter></paramdef> - <paramdef>int - <parameter> - <optional>length</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_slice</function> returns a sequence of elements - from the <parameter>array</parameter> specified by the - <parameter>offset</parameter> and <parameter>length</parameter> - parameters. - </para> - <para> - If <parameter>offset</parameter> is positive, the sequence will - start at that offset in the <parameter>array</parameter>. If - <parameter>offset</parameter> is negative, the sequence will - start that far from the end of the <parameter>array</parameter>. - </para> - <para> - If <parameter>length</parameter> is given and is positive, then - the sequence will have that many elements in it. If - <parameter>length</parameter> is given and is negative then the - sequence will stop that many elements from the end of the - array. If it is omitted, then the sequence will have everything - from <parameter>offset</parameter> up until the end of the - <parameter>array</parameter>. - </para> - <para> - <example> - <title><function>Array_slice</function> examples</title> - <programlisting role="php"> -$input = array ("a", "b", "c", "d", "e"); - -$output = array_slice ($input, 2); // returns "c", "d", and "e" -$output = array_slice ($input, 2, -1); // returns "c", "d" -$output = array_slice ($input, -2, 1); // returns "d" -$output = array_slice ($input, 0, 3); // returns "a", "b", and "c" - </programlisting> - </example> - </para> - <para> - See also <function>array_splice</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-splice"> - <refnamediv> - <refname>array_splice</refname> - <refpurpose> - Remove a portion of the array and replace it with something - else - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_splice</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - <paramdef>int <parameter>offset</parameter></paramdef> - <paramdef>int - <parameter><optional>length</optional></parameter> - </paramdef> - <paramdef>array - <parameter> - <optional>replacement</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_splice</function> removes the elements designated - by <parameter>offset</parameter> and - <parameter>length</parameter> from the - <parameter>input</parameter> array, and replaces them with the - elements of the <parameter>replacement</parameter> array, if - supplied. - </para> - <para> - If <parameter>offset</parameter> is positive then the start of - removed portion is at that offset from the beginning of the - <parameter>input</parameter> array. If - <parameter>offset</parameter> is negative then it starts that far - from the end of the <parameter>input</parameter> array. - </para> - <para> - If <parameter>length</parameter> is omitted, removes everything - from <parameter>offset</parameter> to the end of the array. If - <parameter>length</parameter> is specified and is positive, then - that many elements will be removed. If - <parameter>length</parameter> is specified and is negative then - the end of the removed portion will be that many elements from - the end of the array. Tip: to remove everything from - <parameter>offset</parameter> to the end of the array when - <parameter>replacement</parameter> is also specified, use - <literal>count($input)</literal> for - <parameter>length</parameter>. - </para> - <para> - If <parameter>replacement</parameter> array is specified, then - the removed elements are replaced with elements from this array. - If <parameter>offset</parameter> and - <parameter>length</parameter> are such that nothing is removed, - then the elements from the <parameter>replacement</parameter> - array are inserted in the place specified by the - <parameter>offset</parameter>. Tip: if the replacement is just - one element it is not necessary to put <literal>array()</literal> - around it, unless the element is an array itself. - </para> - <para> - The following equivalences hold: - <programlisting> -array_push ($input, $x, $y) array_splice ($input, count ($input), 0, - array ($x, $y)) -array_pop ($input) array_splice ($input, -1) -array_shift ($input) array_splice ($input, 0, 1) -array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y)) -$a[$x] = $y array_splice ($input, $x, 1, $y) - </programlisting> - </para> - <para> - Returns the array consisting of removed elements. - </para> - <para> - <example> - <title><function>Array_splice</function> examples</title> - <programlisting role="php"> -$input = array ("red", "green", "blue", "yellow"); - -array_splice ($input, 2); // $input is now array ("red", "green") -array_splice ($input, 1, -1); // $input is now array ("red", "yellow") -array_splice ($input, 1, count($input), "orange"); - // $input is now array ("red", "orange") -array_splice ($input, -1, 1, array("black", "maroon")); - // $input is now array ("red", "green", - // "blue", "black", "maroon") - </programlisting> - </example> - </para> - <para> - See also <function>array_slice</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-unique"> - <refnamediv> - <refname>array_unique</refname> - <refpurpose>Removes duplicate values from an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_unique</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_unique</function> takes input - <parameter>array</parameter> and returns a new array - without duplicate values. - Note that keys are preserved. - </para> - <para> - <example> - <title><function>Array_unique</function> example</title> - <programlisting role="php"> -$input = array ("a" => "green", "red", "b" => "green", "blue", "red"); -$result = array_unique ($input); - </programlisting> - </example> - </para> - <para> - This makes <varname>$result</varname> have <literal>array ("a" => - "green", "red", "blue");</literal>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-unshift"> - <refnamediv> - <refname>array_unshift</refname> - <refpurpose> - Push one or more elements onto the beginning of array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_unshift</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - <paramdef>mixed - <parameter> - <optional>...</optional> - </parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Array_unshift</function> prepends passed elements to - the front of the <parameter>array</parameter>. Note that the list - of elements is prepended as a whole, so that the prepended - elements stay in the same order. - </para> - <para> - Returns the new number of elements in the - <parameter>array</parameter>. - </para> - <para> - <example> - <title><function>Array_unshift</function> example</title> - <programlisting role="php"> -$queue = array ("p1", "p3"); -array_unshift ($queue, "p4", "p5", "p6"); - </programlisting> - </example> - </para> - <para> - This would result in <varname>$queue</varname> having 5 - elements: "p4", "p5", "p6", "p1", and "p3". - </para> - <para> - See also <function>array_shift</function>, - <function>array_push</function>, and - <function>array_pop</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-values"> - <refnamediv> - <refname>array_values</refname> - <refpurpose>Return all the values of an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>array_values</function></funcdef> - <paramdef>array <parameter>input</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>array_values</function> returns all the values from the - <parameter>input</parameter> array. - </para> - <para> - <example> - <title><function>Array_values</function> example</title> - <programlisting role="php"> -$array = array ("size" => "XL", "color" => "gold"); -array_values ($array); // returns array ("XL", "gold") - </programlisting> - </example> - </para> - <note> - <para> - This function was added to PHP 4, below is an implementation for - those still using PHP 3. - <example> - <title> - Implementation of <function>array_values</function> for PHP 3 - users - </title> - <programlisting role="php"> -function array_values ($arr) { - $t = array(); - while (list($k, $v) = each ($arr)) { - $t[] = $v; - return $t; - } -} - </programlisting> - </example> - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.array-walk"> - <refnamediv> - <refname>array_walk</refname> - <refpurpose> - Apply a user function to every member of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>array_walk</function></funcdef> - <paramdef>array <parameter>arr</parameter></paramdef> - <paramdef>string <parameter>func</parameter></paramdef> - <paramdef>mixed <parameter>userdata</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <simpara> - Applies the function named by <parameter>func</parameter> to each - element of <parameter>arr</parameter>. - <parameter>func</parameter> will be passed array value as the - first parameter and array key as the second parameter. If - <parameter>userdata</parameter> is supplied, it will be passed as - the third parameter to the user function. - </simpara> - <simpara> - If <parameter>func</parameter> requires more than two or three - arguments, depending on <parameter>userdata</parameter>, a - warning will be generated each time - <function>array_walk</function> calls - <parameter>func</parameter>. These warnings may be suppressed by - prepending the '@' sign to the <function>array_walk</function> - call, or by using <function>error_reporting</function>. - </simpara> - <note> - <para> - If <parameter>func</parameter> needs to be working with the - actual values of the array, specify that the first parameter of - <parameter>func</parameter> should be passed by reference. Then - any changes made to those elements will be made in the array - itself. - </para> - </note> - <note> - <para> - Passing the key and userdata to <parameter>func</parameter> was - added in 4.0. - </para> - <para> - In PHP 4 <function>reset</function> needs to be called as - necessary since <function>array_walk</function> does not reset - the array by default. - </para> - </note> - <para> - <example> - <title><function>Array_walk</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); - -function test_alter (&$item1, $key, $prefix) { - $item1 = "$prefix: $item1"; -} - -function test_print ($item2, $key) { - echo "$key. $item2<br>\n"; -} - -array_walk ($fruits, 'test_print'); -reset ($fruits); -array_walk ($fruits, 'test_alter', 'fruit'); -reset ($fruits); -array_walk ($fruits, 'test_print'); - </programlisting> - </example> - </para> - <simpara> - See also <function>each</function> and <function>list</function>. - </simpara> - </refsect1> - </refentry> - - <refentry id="function.arsort"> - <refnamediv> - <refname>arsort</refname> - <refpurpose> - Sort an array in reverse order and maintain index association - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>arsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. - <example> - <title><function>Arsort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -arsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key = $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[a] = orange -fruits[d] = lemon -fruits[b] = banana -fruits[c] = apple - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in reverse alphabetical order, and - the index associated with each element has been maintained. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also: <function>asort</function>, <function>rsort</function>, - <function>ksort</function>, and <function>sort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.asort"> - <refnamediv> - <refname>asort</refname> - <refpurpose>Sort an array and maintain index association</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>asort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. - <example> - <title><function>Asort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -asort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key = $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[c] = apple -fruits[b] = banana -fruits[d] = lemon -fruits[a] = orange - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in alphabetical order, and the index - associated with each element has been maintained. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also <function>arsort</function>, <function>rsort</function>, - <function>ksort</function>, and <function>sort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.compact"> - <refnamediv> - <refname>compact</refname> - <refpurpose> - Create array containing variables and their values - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>compact</function></funcdef> - <paramdef>mixed <parameter>varname</parameter></paramdef> - <paramdef>mixed - <parameter><optional>...</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Compact</function> takes a variable number of - parameters. Each parameter can be either a string containing the - name of the variable, or an array of variable names. The array - can contain other arrays of variable names inside it; - <function>compact</function> handles it recursively. - </para> - <para> - For each of these, <function>compact</function> looks for a - variable with that name in the current symbol table and adds it - to the output array such that the variable name becomes the key - and the contents of the variable become the value for that key. - In short, it does the opposite of <function>extract</function>. - It returns the output array with all the variables added to it. - </para> - <para> - Any strings that are not set will simply be skipped. - </para> - <para> - <example> - <title><function>Compact</function> example</title> - <programlisting role="php"> -$city = "San Francisco"; -$state = "CA"; -$event = "SIGGRAPH"; - -$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>. - </para> - </example> - </para> - <para> - See also <function>extract</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.count"> - <refnamediv> - <refname>count</refname> - <refpurpose>Count elements in a variable</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>count</function></funcdef> - <paramdef>mixed <parameter>var</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the number of elements in <parameter>var</parameter>, - which is typically an array (since anything else will have one - element). - </para> - <para> - Returns 1 if the variable is not an array. - </para> - <para> - Returns 0 if the variable is not set. - <warning> - <para> - <function>Count</function> may return 0 for a variable that - isn't set, but it may also return 0 for a variable that has - been initialized with an empty array. Use - <function>isset</function> to test if a variable is set. - </para> - </warning> - </para> - <para> - <example> - <title><function>Count</function> example</title> - <programlisting role="php"> -$a[0] = 1; -$a[1] = 3; -$a[2] = 5; -$result = count ($a); -//$result == 3 - </programlisting> - </example> - </para> - <para> - See also: <function>sizeof</function>, - <function>isset</function>, and - <function>is_array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.current"> - <refnamediv> - <refname>current</refname> - <refpurpose>Return the current element in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>current</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Every array has an internal pointer to its "current" element, - which is initialized to the first element inserted into the - array. - </para> - <para> - The <function>current</function> function simply returns the - 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, - <function>current</function> returns <literal>FALSE</literal>. - <warning> - <para> - If the array contains empty elements (0 or "", the empty - string) then this function will return <literal>FALSE</literal> - 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 <function>current</function>. To properly - traverse an array that may contain empty elements, use the - <function>each</function> function. - </para> - </warning> - </para> - <para> - See also: <function>end</function>, <function>next</function>, - <function>prev</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.each"> - <refnamediv> - <refname>each</refname> - <refpurpose> - Return the next key and value pair from an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>each</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the current key and value pair from the array - <parameter>array</parameter> and advances the array cursor. This - pair is returned in a four-element array, with the keys - <emphasis>0</emphasis>, <emphasis>1</emphasis>, - <emphasis>key</emphasis>, and - <emphasis>value</emphasis>. Elements <emphasis>0</emphasis> and - <emphasis>key</emphasis> contain the key name of the array - element, and <emphasis>1</emphasis> and - <emphasis>value</emphasis> contain the data. - </para> - <para> - If the internal pointer for the array points past the end of the - array contents, <function>each</function> returns - <literal>FALSE</literal>. - </para> - <para> - <example> - <title><function>Each</function> examples</title> - <programlisting role="php"> -$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese"); -$bar = each ($foo); - </programlisting> - <para> - <varname>$bar</varname> now contains the following key/value - pairs: - <itemizedlist spacing="compact"> - <listitem><simpara>0 => 0</simpara></listitem> - <listitem><simpara>1 => 'bob'</simpara></listitem> - <listitem><simpara>key => 0</simpara></listitem> - <listitem><simpara>value => 'bob'</simpara></listitem> - </itemizedlist> - <programlisting role="php"> -$foo = array ("Robert" => "Bob", "Seppo" => "Sepi"); -$bar = each ($foo); - </programlisting> - </para> - <para> - <varname>$bar</varname> now contains the following key/value - pairs: - <itemizedlist spacing="compact"> - <listitem><simpara>0 => 'Robert'</simpara></listitem> - <listitem><simpara>1 => 'Bob'</simpara></listitem> - <listitem><simpara>key => 'Robert'</simpara></listitem> - <listitem><simpara>value => 'Bob'</simpara></listitem> - </itemizedlist> - </para> - </example> - </para> - <para> - <function>Each</function> is typically used in conjunction with - <function>list</function> to traverse an array; for instance, - <varname>$HTTP_POST_VARS</varname>: - <example> - <title> - Traversing <varname>$HTTP_POST_VARS</varname> with - <function>each</function> - </title> - <programlisting role="php"> -echo "Values submitted via POST method:<br>"; -reset ($HTTP_POST_VARS); -while (list ($key, $val) = each ($HTTP_POST_VARS)) { - echo "$key => $val<br>"; -} - </programlisting> - </example> - </para> - <para> - After <function>each</function> has executed, the array cursor - will be left on the next element of the array, or on the last - element if it hits the end of the array. - </para> - <para> - See also <function>key</function>, <function>list</function>, - <function>current</function>, <function>reset</function>, - <function>next</function>, and <function>prev</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.end"> - <refnamediv> - <refname>end</refname> - <refpurpose> - Set the internal pointer of an array to its last element - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>end</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>End</function> advances <parameter>array</parameter>'s - internal pointer to the last element, and returns that element. - </para> - <para> - See also: <function>current</function>, - <function>each</function>, <function>end</function>, - <function>next</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.extract"> - <refnamediv> - <refname>extract</refname> - <refpurpose> - Import variables into the symbol table from an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>extract</function></funcdef> - <paramdef>array <parameter>var_array</parameter></paramdef> - <paramdef>int - <parameter><optional>extract_type</optional></parameter> - </paramdef> - <paramdef>string - <parameter><optional>prefix</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function is used to import variables from an array into the - current symbol table. It takes associative array - <parameter>var_array</parameter> and treats keys as variable - names and values as variable values. For each key/value pair it - will create a variable in the current symbol table, subject to - <parameter>extract_type</parameter> and - <parameter>prefix</parameter> parameters. - </para> - <note> - <para> - Since version 4.0.5 this function returns the number of - variables extracted. - </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 - following values: - <variablelist> - <varlistentry> - <term>EXTR_OVERWRITE</term> - <listitem> - <simpara> - If there is a collision, overwrite the existing variable. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_SKIP</term> - <listitem> - <simpara> - If there is a collision, don't overwrite the existing - variable. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_PREFIX_SAME</term> - <listitem> - <simpara>If there is a collision, prefix the variable name with - <parameter>prefix</parameter>. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <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. - </simpara> - </listitem> - </varlistentry> - <varlistentry> - <term>EXTR_PREFIX_INVALID</term> - <listitem> - <simpara> - Only prefix invalid/numeric variable names with - <parameter>prefix</parameter>. This flag has been added in PHP 4.0.5. - </simpara> - </listitem> - </varlistentry> - </variablelist> - </para> - <para> - If <parameter>extract_type</parameter> is not specified, it is - assumed to be EXTR_OVERWRITE. - </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. - </para> - <para> - <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 - variables contained in an associative array returned by - <function>wddx_deserialize</function>. - </para> - <para> - <example> - <title><function>Extract</function> example</title> - <programlisting role="php"> -<?php - -/* Suppose that $var_array is an array returned from - wddx_deserialize */ - -$size = "large"; -$var_array = array ("color" => "blue", - "size" => "medium", - "shape" => "sphere"); -extract ($var_array, EXTR_PREFIX_SAME, "wddx"); - -print "$color, $size, $shape, $wddx_size\n"; - -?> - </programlisting> - </example> - </para> - <para> - The above example will produce: - <programlisting> -blue, large, sphere, medium - </programlisting> - </para> - <para> - The <varname>$size</varname> wasn't overwritten, becaus we - specified EXTR_PREFIX_SAME, which resulted in - <varname>$wddx_size</varname> being created. If EXTR_SKIP was - specified, then $wddx_size wouldn't even have been created. - EXTR_OVERWRITE would have cause <varname>$size</varname> to have - value "medium", and EXTR_PREFIX_ALL would result in new variables - being named <varname>$wddx_color</varname>, - <varname>$wddx_size</varname>, and - <varname>$wddx_shape</varname>. - </para> - <para> - You must use an associative array, a numerically indexed array - will not produce results. - </para> - <para> - See also: <function>compact</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.in-array"> - <refnamediv> - <refname>in_array</refname> - <refpurpose>Return TRUE if a value exists in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>bool in_array</funcdef> - <paramdef>mixed <parameter>needle</parameter></paramdef> - <paramdef>array <parameter>haystack</parameter></paramdef> - <paramdef>bool <parameter>strict</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Searches <parameter>haystack</parameter> for - <parameter>needle</parameter> and returns <literal>TRUE</literal> - if it is found in the array, <literal>FALSE</literal> otherwise. - </para> - <para> - If the third parameter <parameter>strict</parameter> is set to - <literal>TRUE</literal> then the <function>in_array</function> - will also check the types of the <parameter>needle</parameter> - in the <parameter>haystack</parameter>. - </para> - <para> - <example> - <title><function>In_array</function> example</title> - <programlisting role="php"> -$os = array ("Mac", "NT", "Irix", "Linux"); -if (in_array ("Irix", $os)){ - print "Got Irix"; - } - </programlisting> - </example> - </para> - <para> - <example> - <title><function>In_array</function> with strict example</title> - <programlisting role="php"> -<?php -$a = array('1.10', 12.4, 1.13); - -if (in_array('12.4', $a, TRUE)) - echo "'12.4' found with strict check\n"; -if (in_array(1.13, $a, TRUE)) - echo "1.13 found with strict check\n"; -?> - -// This will output: - -1.13 found with strict check - </programlisting> - </example> - </para> - <para> - See also <function>array_search</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.array-search"> - <refnamediv> - <refname>array_search</refname> - <refpurpose> - Searches the array for a given value and returns the corresponding key if successful - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>array_search</function></funcdef> - <paramdef>mixed <parameter>needle</parameter></paramdef> - <paramdef>array <parameter>haystack</parameter></paramdef> - <paramdef>bool <parameter>strict</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Searches <parameter>haystack</parameter> for - <parameter>needle</parameter> and returns the key if it is found in - the array, <literal>FALSE</literal> otherwise. - </para> - <para> - If the third parameter <parameter>strict</parameter> is set to - <literal>TRUE</literal> then the <function>array_search</function> - will also check the types of the <parameter>needle</parameter> - in the <parameter>haystack</parameter>. - </para> - <para> - See also <function>in_array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.key"> - <refnamediv> - <refname>key</refname> - <refpurpose>Fetch a key from an associative array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>key</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Key</function> returns the index element of the - current array position. - </para> - <para> - See also <function>current</function> and <function>next</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.krsort"> - <refnamediv> - <refname>krsort</refname> - <refpurpose>Sort an array by key in reverse order</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>krsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Sorts an array by key in reverse order, maintaining key to data - correlations. This is useful mainly for associative arrays. - <example> - <title><function>Krsort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -krsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[d] = lemon -fruits[c] = apple -fruits[b] = banana -fruits[a] = orange - </programlisting> - </informalexample> - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <simpara> - See also <function>asort</function>, <function>arsort</function>, - <function>ksort</function> <function>sort</function>, - <function>natsort</function>and <function>rsort</function>. - </simpara> - </refsect1> - </refentry> - - <refentry id="function.ksort"> - <refnamediv> - <refname>ksort</refname> - <refpurpose>Sort an array by key</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>ksort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - Sorts an array by key, maintaining key to data correlations. This - is useful mainly for associative arrays. - <example> - <title><function>Ksort</function> example</title> - <programlisting role="php"> -$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); -ksort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[a] = orange -fruits[b] = banana -fruits[c] = apple -fruits[d] = lemon - </programlisting> - </informalexample> - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <simpara> - See also <function>asort</function>, <function>arsort</function>, - <function>sort</function>, <function>natsort</function>, and - <function>rsort</function>. - </simpara> - <note> - <para> - The second parameter was added in PHP 4. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.list"> - <refnamediv> - <refname>list</refname> - <refpurpose> - Assign variables as if they were an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>list</function></funcdef> - <varargs/> - </funcprototype> - </funcsynopsis> - <para> - Like <function>array</function>, this is not really a function, - but a language construct. <function>list</function> is used to - assign a list of variables in one operation. - <example> - <title><function>List</function> example</title> - <programlisting role="php"> -<table> - <tr> - <th>Employee name</th> - <th>Salary</th> - </tr> - -<?php - -$result = mysql ($conn, "SELECT id, name, salary FROM employees"); -while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { - print (" <tr>\n". - " <td><a href=\"info.php3?id=$id\">$name</a></td>\n". - " <td>$salary</td>\n". - " </tr>\n"); -} - -?> - -</table> - </programlisting> - </example> - </para> - <para> - See also <function>each</function> and <function>array</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.natsort"> - <refnamediv> - <refname>natsort</refname> - <refpurpose> - Sort an array using a "natural order" algorithm - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>natsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function implements a sort algorithm that orders - alphanumeric strings in the way a human being would. This is - described as a "natural ordering". An example of the difference - between this algorithm and the regular computer string sorting - algorithms (used in <function>sort</function>) can be seen below: - </para> - <para> - <example> - <title><function>natsort</function> example</title> - <programlisting role="php"> -$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); - -sort($array1); -echo "Standard sorting\n"; -print_r($array1); - -natsort($array2); -echo "\nNatural order sorting\n"; -print_r($array2); - </programlisting> - </example> - </para> - <para> - The code above will generate the following output: - </para> - <para> - <informalexample> - <programlisting> -Standard sorting -Array -( - [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 -) - </programlisting> - </informalexample> - For more infomation see: Martin Pool's <ulink - url="&url.strnatcmp;">Natural Order String Comparison</ulink> - page. - </para> - <para> - See also <function>natcasesort</function>, - <function>strnatcmp</function> and - <function>strnatcasecmp</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.natcasesort"> - <refnamediv> - <refname>natcasesort</refname> - <refpurpose> - Sort an array using a case insensitive "natural order" algorithm - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>natcasesort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function implements a sort algorithm that orders - alphanumeric strings in the way a human being would. This is - described as a "natural ordering". - </para> - <para> - <function>natcasesort</function> is a case insensitive version of - <function>natsort</function>. See <function>natsort</function> - for an example of the difference between this algorithm and the - regular computer string sorting algorithms. - </para> - <para> - For more infomation see: Martin Pool's <ulink - url="&url.strnatcmp;">Natural Order String Comparison</ulink> - page. - </para> - <para> - See also <function>sort</function>, - <function>natsort</function>, - <function>strnatcmp</function> and - <function>strnatcasecmp</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.next"> - <refnamediv> - <refname>next</refname> - <refpurpose> - Advance the internal array pointer of an array - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>next</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the array element in the next place that's pointed by the - internal array pointer, or <literal>FALSE</literal> if - there are no more elements. - </para> - <para> - <function>Next</function> behaves like - <function>current</function>, with one difference. It advances - the internal array pointer one place forward before returning the - 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, <function>next</function> returns <literal>FALSE</literal>. - <warning> - <para> - If the array contains empty elements, or elements that have a key - value of 0 then this function will return <literal>FALSE</literal> - for these elements as well. To properly traverse an array which - may contain empty elements or elements with key values of 0 see the - <function>each</function> function. - </para> - </warning> - </para> - <para> - See also: - <function>current</function>, <function>end</function>, - <function>prev</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.pos"> - <refnamediv> - <refname>pos</refname> - <refpurpose>Get the current element from an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>pos</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <simpara> - This is an alias for <function>current</function>. - </simpara> - <para> - See also: - <function>end</function>, <function>next</function>, - <function>prev</function> and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.prev"> - <refnamediv> - <refname>prev</refname> - <refpurpose>Rewind the internal array pointer</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>prev</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the array element in the previous place that's pointed by - the internal array pointer, or <literal>FALSE</literal> if there are no more - elements. - <warning> - <para> - If the array contains empty elements then this function will - return <literal>FALSE</literal> for these elements as well. - To properly traverse an array which may contain empty elements - see the <function>each</function> function. - </para> - </warning> - </para> - <para> - <function>Prev</function> behaves just like - <function>next</function>, except it rewinds the internal array - pointer one place instead of advancing it. - </para> - <para> - See also: <function>current</function>, <function>end</function>, - <function>next</function>, and <function>reset</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.range"> - <refnamediv> - <refname>range</refname> - <refpurpose> - Create an array containing a range of integers - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>array <function>range</function></funcdef> - <paramdef>int <parameter>low</parameter></paramdef> - <paramdef>int <parameter>high</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Range</function> returns an array of integers from - <parameter>low</parameter> to <parameter>high</parameter>, - inclusive. - </para> - <para> - See <function>shuffle</function> for an example of its use. - </para> - </refsect1> - </refentry> - - <refentry id="function.reset"> - <refnamediv> - <refname>reset</refname> - <refpurpose> - Set the internal pointer of an array to its first element - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>mixed <function>reset</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - <function>Reset</function> rewinds <parameter>array</parameter>'s - internal pointer to the first element. - </para> - <para> - <function>Reset</function> returns the value of the first array - element. - </para> - <para> - See also: <function>current</function>, - <function>each</function>, <function>next</function>, - and <function>prev</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.rsort"> - <refnamediv> - <refname>rsort</refname> - <refpurpose>Sort an array in reverse order</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>rsort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int - <parameter><optional>sort_flags</optional></parameter> - </paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array in reverse order (highest to lowest). - <example> - <title><function>Rsort</function> example</title> - <programlisting role="php"> -$fruits = array ("lemon", "orange", "banana", "apple"); -rsort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "$key -> $val\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[0] = orange -fruits[1] = lemon -fruits[2] = banana -fruits[3] = apple - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in reverse alphabetical order. - </para> - <para> - You may modify the behavior of the sort using the optional - parameter <parameter>sort_flags</parameter>, for details - see <function>sort</function>. - </para> - <para> - See also: <function>arsort</function>, - <function>asort</function>, <function>ksort</function>, - <function>sort</function>, and <function>usort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.shuffle"> - <refnamediv> - <refname>shuffle</refname> - <refpurpose>Shuffle an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>shuffle</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function shuffles (randomizes the order of the elements in) - an array. You must use <function>srand</function> to seed this - function. - <example> - <title><function>Shuffle</function> example</title> - <programlisting role="php"> -$numbers = range (1,20); -srand ((double)microtime()*1000000); -shuffle ($numbers); -while (list (, $number) = each ($numbers)) { - echo "$number "; -} - </programlisting> - </example> - </para> - <para> - See also <function>arsort</function>, <function>asort</function>, - <function>ksort</function>, <function>rsort</function>, - <function>sort</function> and <function>usort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.sizeof"> - <refnamediv> - <refname>sizeof</refname> - <refpurpose>Get the number of elements in an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>int <function>sizeof</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - Returns the number of elements in the array. - </para> - <para> - See also <function>count</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.sort"> - <refnamediv> - <refname>sort</refname> - <refpurpose>Sort an array</refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>sort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>int <parameter><optional>sort_flags</optional></parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array. Elements will be arranged from - lowest to highest when this function has completed. - <example> - <title><function>Sort</function> example</title> - <programlisting role="php"> -<?php - -$fruits = array ("lemon", "orange", "banana", "apple"); -sort ($fruits); -reset ($fruits); -while (list ($key, $val) = each ($fruits)) { - echo "fruits[".$key."] = ".$val; -} - -?> - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -fruits[0] = apple -fruits[1] = banana -fruits[2] = lemon -fruits[3] = orange - </programlisting> - </informalexample> - </para> - <para> - The fruits have been sorted in alphabetical order. - </para> - <para> - The optional second parameter <parameter>sort_flags</parameter> - may be used to modify the sorting behavior using theese valies: - </para> - <para> - Sorting type flags: - <itemizedlist> - <listitem> - <simpara>SORT_REGULAR - compare items normally</simpara> - </listitem> - <listitem> - <simpara>SORT_NUMERIC - compare items numerically</simpara> - </listitem> - <listitem> - <simpara>SORT_STRING - compare items as strings</simpara> - </listitem> - </itemizedlist> - </para> - <para> - See also: <function>arsort</function>, - <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>. - </para> - <note> - <para> - The second parameter was added in PHP 4. - </para> - </note> - </refsect1> - </refentry> - - <refentry id="function.uasort"> - <refnamediv> - <refname>uasort</refname> - <refpurpose> - Sort an array with a user-defined comparison function and - maintain index association - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>uasort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>function <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function sorts an array such that array indices maintain - their correlation with the array elements they are associated - with. This is used mainly when sorting associative arrays where - the actual element order is significant. The comparison function - is user-defined. - </para> - <note> - <para> - Please see <function>usort</function> and - <function>uksort</function> for examples of user-defined - comparison functions. - </para> - </note> - <para> - See also: <function>usort</function>, <function>uksort</function>, - <function>sort</function>, <function>asort</function>, - <function>arsort</function>, <function>ksort</function> - and <function>rsort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.uksort"> - <refnamediv> - <refname>uksort</refname> - <refpurpose> - Sort an array by keys using a user-defined comparison function - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>uksort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>function <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function will sort the keys of an array using a - user-supplied comparison function. If the array you wish to sort - needs to be sorted by some non-trivial criteria, you should use - this function. - </para> - <para> - <example> - <title><function>Uksort</function> example</title> - <programlisting role="php"> -function cmp ($a, $b) { - if ($a == $b) return 0; - return ($a > $b) ? -1 : 1; -} - -$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); - -uksort ($a, "cmp"); - -while (list ($key, $value) = each ($a)) { - echo "$key: $value\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -20: twenty -10: ten -4: four -3: three - </programlisting> - </informalexample> - </para> - <para> - See also: <function>usort</function>, <function>uasort</function>, - <function>sort</function>, <function>asort</function>, - <function>arsort</function>, <function>ksort</function>, - <function>natsort</function> and <function>rsort</function>. - </para> - </refsect1> - </refentry> - - <refentry id="function.usort"> - <refnamediv> - <refname>usort</refname> - <refpurpose> - Sort an array by values using a user-defined comparison function - </refpurpose> - </refnamediv> - <refsect1> - <title>Description</title> - <funcsynopsis> - <funcprototype> - <funcdef>void <function>usort</function></funcdef> - <paramdef>array <parameter>array</parameter></paramdef> - <paramdef>string <parameter>cmp_function</parameter></paramdef> - </funcprototype> - </funcsynopsis> - <para> - This function will sort an array by its values using a - user-supplied comparison function. If the array you wish to sort - needs to be sorted by some non-trivial criteria, you should use - this function. - </para> - <para> - The comparison function must return an integer less than, equal - to, or greater than zero if the first argument is considered to - be respectively less than, equal to, or greater than the - second. If two members compare as equal, their order in the - sorted array is undefined. - </para> - <para> - <example> - <title><function>Usort</function> example</title> - <programlisting role="php"> -function cmp ($a, $b) { - if ($a == $b) return 0; - return ($a > $b) ? -1 : 1; -} - -$a = array (3, 2, 5, 6, 1); - -usort ($a, "cmp"); - -while (list ($key, $value) = each ($a)) { - echo "$key: $value\n"; -} - </programlisting> - </example> - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -0: 6 -1: 5 -2: 3 -3: 2 -4: 1 - </programlisting> - </informalexample> - </para> - <note> - <para> - Obviously in this trivial case the <function>rsort</function> - function would be more appropriate. - </para> - </note> - <para> - <example> - <title> - <function>Usort</function> example using multi-dimensional array - </title> - <programlisting role="php"> -function cmp ($a, $b) { - return strcmp($a["fruit"],$b["fruit"]); -} - -$fruits[0]["fruit"] = "lemons"; -$fruits[1]["fruit"] = "apples"; -$fruits[2]["fruit"] = "grapes"; - -usort($fruits, "cmp"); - -while (list ($key, $value) = each ($fruits)) { - echo "\$fruits[$key]: " . $value["fruit"] . "\n"; -} - </programlisting> - </example> - </para> - <para> - When sorting a multi-dimensional array, $a and $b contain - references to the first index of the array. - </para> - <para> - This example would display: - </para> - <para> - <informalexample> - <programlisting> -$fruits[0]: apples -$fruits[1]: grapes -$fruits[2]: lemons - </programlisting> - </informalexample> - </para> - <para> - <warning> - <para> - The underlying quicksort function in some C libraries (such as - on Solaris systems) may cause PHP to crash if the comparison - function does not return consistent values. - </para> - </warning> - </para> - <para> - 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> - </refsect1> - </refentry> - - </reference> - -<!-- Keep this comment at the end of the file -Local variables: -mode: sgml -sgml-omittag:t -sgml-shorttag:t -sgml-minimize-attributes:nil -sgml-always-quote-attributes:t -sgml-indent-step:1 -sgml-indent-data:t -sgml-parent-document:nil -sgml-default-dtd-file:"../../manual.ced" -sgml-exposed-tags:nil -sgml-local-catalogs:nil -sgml-local-ecat-files:nil -End: ---> +<reference id="ref.array"> + <title>ë°°ì´í¨ì</title> + <titleabbrev>ë°°ì´</titleabbrev> + <partintro> + <simpara> + ì´ í¨ìë ë¤ìí ë°©ë²ì¼ë¡ ë°°ì´ì ë¤ë£¨ê³ , ìí¸ìì©í ì ìê² í´ ì¤ë¤. + ë°°ì´ì ë³ìë¤ì ì§í©ì ìí , ì²ë¦¬, ì¡°ì íëë° íìì ì´ë¤. + </simpara> + <simpara> + ì¼ì°¨ìë° ë¤ì°¨ì ë°°ì´ì ì¬ì©ì´ ê°ë¥íë©°, ì¬ì©ìë ë¤ë¥¸ í¨ìë¡ ë¶í° ìì±ë ì ìë¤. + ë°ì´í°ë² ì´ì¤ì 쿼리문ì¼ë¡ ë¶í° ë°°ì´ì ìì±ì ìí ëªëª í¹ë³í ë°ì´í°ë² ì´ì¤ í¸ë¤ë§ í¨ìê° ìê³ ëªëª í¨ìë¤ì 리í´ê°ì¼ë¡ ë°°ì´ì ë°ííë¤. + </simpara> + <para> + <function>is_array</function>, <function>explode</function>, + <function>implode</function>, <function>split</function> + ê·¸ë¦¬ê³ <function>join</function>ì 참조íë¼. + </para> + </partintro> + <refentry id="function.array"> + <refnamediv> + <refname>array</refname> + <refpurpose> + ë°°ì´ì ìì±íë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array</function> + </funcdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + íë¼ë¯¸í°ì ë°°ì´ì ë°ííë¤. íë¼ë¯¸í°ë<literal>=></literal> ì°ì°ì를 ê°ì§ ì¸ë±ì¤ë¡ 주ì´ì§ ìë ìë¤. + </para> + <para> + <note> + <para> + <function>Array</function> is a language construct used to + represent literal arrays, and not a regular function. + </para> + </note> + </para> + <para> + "index => values" 구문ì comma(,)ë¡ êµ¬ë¶ëë©°, ì¸ë±ì¤ì ê°ì ì ìíë¤. + ì¸ë±ì¤ê°ì¼ë¡ë 문ìí í¹ì ì«ìíì´ ì°ì¸ë¤. ì¸ë±ì¤ ê°ì´ ìëµëì ì ê²½ì° + ì ì 0ì¼ë¡ ììëë ì¸ë±ì¤ê° ìëì¼ë¡ ìì±ëë¤. ì¸ë±ì¤ê° ì ìë¼ë©´ + ë¤ìì ìì±ëë ì¸ë±ì¤ë (ê°ì¥ í° ì¸ë±ì¤ê° + 1) ì ê°ì´ ëë¤. + ëê°ì ëì¼í ì¸ë±ì¤ê° ì ìëìì ê²½ì°, ë§ì§ë§ ê°ì´ ì²ì ê°ì ë®ì´ì°ê² ë¨ì ì ìíë¼. + </para> + <para> + ë¤ìì ìë 2ì°¨ì ë°°ì´ì ìì±íë ë°©ë²ê³¼, associative ë°°ì´ì í¤(key)ê°ì ì§ì íë ë°©ë² + , ì«ì ì¸ë±ì¤ê° ë°°ì´ìì ì´ë¤ ê·ì¹ì¼ë¡ ìì± ëëì§ë¥¼ ì¤ëª íë¤. + <example> + <title> + <function>Array</function> example</title> + <programlisting role="php"> +$fruits = array ( + "fruits" => array ("a"=>"orange", "b"=>"banana", "c"=>"apple"), + "numbers" => array (1, 2, 3, 4, 5, 6), + "holes" => array ("first", 5 => "second", "third") +); + </programlisting> + </example> + </para> + <para> + <example> + <title> + <function>Array</function>í¨ììì ì¸ë±ì¤ì ìëìì± + </title> + <programlisting role="php"> +$array = array( 1, 1, 1, 1, 1, 8=>1, 4=>1, 19, 3=>13); +print_r($array); + </programlisting> + </example> + ë¤ìì ì¶ë ¥í ê²ì´ë¤. : + <informalexample> + <programlisting> +Array +( + [0] => 1 + [1] => 1 + [2] => 1 + [3] => 13 + [4] => 1 + [8] => 1 + [9] => 19 +) + </programlisting> + </informalexample> + ì¸ë±ì¤ '3'ì ëí´ ê°ì´ ëë² ì ìëìì¼ë©°, ì¸ë±ì¤ '3'ì í´ë¹íë ìµì¢ ê°ì ë§ì§ë§ì ì ìë 13ì´ ëë¤. + ì¸ë±ì¤ '4'ê° ì ìë íì ì¸ë±ì¤ '8' ì´ ì ìëìê³ ë¤ìì ìì±ë ì¸ë±ì¤(ê° 19를 ê°ì§ë¤)ë + ê°ì¥ í° ì¸ë±ì¤ ê°ì´ 8ì´ìì¼ë¯ë¡ 9ê° ëë¤ë ì ì ì ìíë¼. + </para> + <para> + ì¼ì°¨ì ë°°ì´ ìì±ì ì. + <example> + <title> + <function>Array</function>ììì 1ì°¨ìë°°ì´ ì¸ë±ì¤ + </title> + <programlisting role="php"> + $firstquarter = array(1 => 'January', 'February', 'March'); + print_r($firstquarter); + </programlisting> + </example> + ë¤ìì ì¶ë ¥í ê²ì´ë¤. : + <informalexample> + <programlisting> +Array +( + [1] => 'January' + [2] => 'February' + [3] => 'March' +) + </programlisting> + </informalexample> + </para> + <para> + <function>list</function>를 ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-count-values"> + <refnamediv> + <refname>array_count_values</refname> + <refpurpose>ë°°ì´ ê°ì ì를 ì¼ë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_count_values</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_count_values</function> ë <parameter>input</parameter> ë°°ì´ì ê°ì + í¤ë¡ ê°ê³ ê·¸ ê°ë¤ì ë¹ë를 ê°ì¼ë¡ ê°ë ë°°ì´ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_count_values</function>ì</title> + <programlisting role="php"> +$array = array (1, "hello", 1, "world", "hello"); +array_count_values ($array); // array (1=>2, "hello"=>2, "world"=>1) ì ë°ííë¤. + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-diff"> + <refnamediv> + <refname>array_diff</refname> + <refpurpose>ë°°ì´ì ì°¨ì´ì ê³ì°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_diff</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional> ...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_diff</function>ë ì¸ìë¡ ì¨ <parameter>array1</parameter>ì´ì¸ì + ë°°ì´ì ê°ê³¼ ì¤ë³µëì§ ìë <parameter>array1</parameter>ì ê°ì í¬í¨íë ë°°ì´ì ë°ííë¤. + í¤(keys)ë ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_diff</function> ì</title> + <programlisting role="php"> +$array1 = array ("a" => "green", "red", "blue"); +$array2 = array ("b" => "green", "yellow", "red"); +$result = array_diff ($array1, $array2); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname> ê° <literal>array ("blue");</literal>를 ê°ì§ê² ëë¤. + </para> + <para> + <function>array_intersect</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-flip"> + <refnamediv> + <refname>array_flip</refname> + <refpurpose>Flip all the values of an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_flip</function> + </funcdef> + <paramdef>array <parameter>trans</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_flip</function> returns an array in flip order. + </para> + <para> + <example> + <title> + <function>Array_flip</function> example</title> + <programlisting role="php"> +$trans = array_flip ($trans); +$original = strtr ($str, $trans); + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-intersect"> + <refnamediv> + <refname>array_intersect</refname> + <refpurpose>ë°°ì´ì ì¤ë³µì ê³ì°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_intersect</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional> ...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_intersect</function>ë ì¸ìë¡ ì¨ ëª¨ë ë°°ì´ì ì¡´ì¬íë <parameter>array1</parameter>ì ê°ì 모ë í¬í¨íë ë°°ì´ì ë°ííë¤. + í¤ë ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_intersect</function> ì</title> + <programlisting role="php"> +$array1 = array ("a" => "green", "red", "blue"); +$array2 = array ("b" => "green", "yellow", "red"); +$result = array_intersect ($array1, $array2); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname>ë <literal>array ("a" + => "green", "red");</literal>ì´ ëë¤. + </para> + <para> + <function>array_diff</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-keys"> + <refnamediv> + <refname>array_keys</refname> + <refpurpose>ë°°ì´ì 모ë í¤ê°ì ë°ííë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_keys</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>search_value</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_keys</function> ë <parameter>input</parameter> ë°°ì´ë¡ ë¶í° ì«ìíê³¼ 문ìíì í¤ë¥¼ ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ìµì ì¸ <parameter>search_value</parameter>ì´ ì§ì ëë¤ë©´, ê·¸ ê°ì ê°ì§ë í¤ë§ì´ ë°íëê³ ìëµëë©´ <parameter>input</parameter> ì 모ë í¤ê° ë°°ì´ë¡ ë°íëë¤. + </para> + <para> + <example> + <title> + <function>Array_keys</function> ì</title> + <programlisting role="php"> +$array = array (0 => 100, "color" => "red"); +array_keys ($array); // array (0, "color") ì ë°ííë¤. + +$array = array ("blue", "red", "green", "blue", "blue"); +array_keys ($array, "blue"); // array (0, 3, 4) ì ë°ííë¤. + </programlisting> + </example> + </para> + <note> + <para> + ì´ í¨ìë PHP 4ìì ì¶ê°ëìì¼ë©°, ìëë ì¬ì í PHP3ì ì¬ì©íë ì¬ì©ì를 ìí ì´ í¨ìì 구íë¶ë¶ì´ë¤. + <example> + <title> + PHP 3 ì¬ì©ìë¤ì ìí <function>array_keys</function>ì 구í + </title> + <programlisting role="php"> +function array_keys ($arr, $term="") { + $t = array(); + while (list($k,$v) = each($arr)) { + if ($term && $v != $term) + continue; + $t[] = $k; + } + return $t; +} + </programlisting> + </example> + </para> + </note> + <para> + <function>array_values</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-merge"> + <refnamediv> + <refname>array_merge</refname> + <refpurpose>ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_merge</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_merge</function> ë ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë©°, + ê°ì ì´ì ë°°ì´ì ëì ë¶ì´ ì¶ê°ëë¤. ê·¸ 결과를 ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ë§ì½ ì ë ¥ë ë°°ì´ì´ ê°ì 문ìì´ í¤ë¥¼ ê°ì§ë¤ë©´, ê·¸ í¤ì ëí´ ëì¤ì ì¨ ê°ì´ ì´ì ì ê°ì ëì²´íë¤. + ê·¸ë¬ë ì ë ¥ë ë°°ì´ì´ ê°ì ì«ì í¤ë¥¼ ê°ì§ë¤ë©´, ëì¤ ê°ì´ ì²ìê°ì ëì²´íì§ ìê³ ëì¤ ê°ì ë°°ì´ì ë¤ì ì¶ê°ê° ëë¤. + </para> + <para> + <example> + <title> + <function>array_merge</function> ì</title> + <programlisting role="php"> +$array1 = array ("color" => "red", 2, 4); +$array2 = array ("a", "b", "color" => "green", "shape" => "trapezoid", 4); +array_merge ($array1, $array2); + </programlisting> + </example> + </para> + <para> + ê²°ê³¼ë¡ ëíëë ë°°ì´ì <literal>array("color" => "green", 2, 4, + "a", "b", "shape" => "trapezoid", 4)</literal>ì´ ëë¤. + </para> + <para> + <function>array_merge_recursive</function>ì ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-merge-recursive"> + <refnamediv> + <refname>array_merge_recursive</refname> + <refpurpose>ì¬ê·ì ì¼ë¡ ëê° í¹ì ê·¸ ì´ìì ë°°ì´ì ë³í©íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_merge_recursive</function> + </funcdef> + <paramdef>array <parameter>array1</parameter> + </paramdef> + <paramdef>array <parameter>array2</parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_merge_recursive</function> ë ëê° ì´ìì ë°°ì´ ìì를 ë³í©íì¬ ê°ì ì´ì ë°°ì´ì ì¶ê°íê³ ì´ë¥¼ ë°°ì´ë¡ ë°ííë¤. + </para> + <para> + ì ë ¥ë ë°°ì´ì ê°ì 문ìì´ í¤ê° ìì¼ë©´, ì´ í¤ë ë°°ì´ë¡ í©ì³ì§ê³ ì´ë ì¬ê·ì ì¼ë¡ ì§íëë¤. + ë°°ì´ì ê°ì¼ë¡ ê°ë ê²½ì° ê°ì ë°©ìì¼ë¡ ê° ê°ì ë°°ì´ì ë³í©íë¤. + ê·¸ë¬ë ë°°ì´ì´ ê°ì ì«ì í¤ë¥¼ ê°ì§ë¤ë©´ ëì¼ ì«ìí¤ì ê°ì ë®ì´ì°ë ê²ì´ ìëë¼ ì´ì ë°°ì´ì ë¤ì ì¶ê° ëë¤. + </para> + <para> + <example> + <title> + <function>Array_merge_recursive</function> ì</title> + <programlisting role="php"> +$ar1 = array ("color" => array ("favorite" => "red"), 5); +$ar2 = array (10, "color" => array ("favorite" => "green", "blue")); +$result = array_merge_recursive ($ar1, $ar2); + </programlisting> + </example> + </para> + <para> + <literal>array ("color" => array + ("favorite" => array ("red", "green"), "blue"), 5, 10)</literal>ì 결과를 ê°ëë¤. + </para> + <para> + <function>array_merge</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-multisort"> + <refnamediv> + <refname>array_multisort</refname> + <refpurpose>ì¬ë¬ê°ì ë°°ì´ í¹ì ë¤ì°¨ì ë°°ì´ì ì ë ¬íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>bool <function>array_multisort</function> + </funcdef> + <paramdef>array <parameter>ar1</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>arg</optional> + </parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_multisort</function> ë ë¤ì¤ ë°°ì´ì ëí´ì ì¬ë¬ê°ì ë°°ì´ì íë²ì ì ë ¬íê±°ë ë¤ì°¨ì ë°°ì´ìì ë´ë¶ì í¬í¨ëë ê°ê°ê°ì ë°°ì´ì ì ë ¬íëë° ì¬ì©ëë¤. + ì ë ¬ë ë í¤ê°ë ì ì§ëë¤. + </para> + <para> + ì ë ¥ë ë°°ì´ì íì ìí´ ì ë ¬íë í ì´ë¸ì ì´ê³¼ë ê°ì´ ìê°í ì ìë¤. - ì´ë SQLì ORDER BYì ê³¼ ê·¸ 기ë¥ì´ ì ì¬íë¤. + 첫ë²ì§¸ ì¤ë ë°°ì´ì´ 먼ì ì ë ¬ ëë¤. ë°°ì´ì í(ê°) + </para> + <para> + ì´ í¨ìì 매ê°ë³ì 구조ë ì½ê° ë í¹íì§ë§, ì ì°íë¤. + ì²ìì 매ê°ë³ìë ë°°ì´ì´ì´ì¼ íë©°, ë¤ìì ëì¤ë ê°ê°ì 매ê°ë³ìë + ë°°ì´ì´ê±°ë í¹ì ë¤ìì ê¸ëê·¸ 리ì¤í¸ì ìë ì ë ¬ íëê·¸ì¼ ì ìë¤. + </para> + <para> + ì ë ¬ ë°©ë² íëê·¸: + <itemizedlist> + <listitem> + <simpara>SORT_ASC - ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬</simpara> + </listitem> + <listitem> + <simpara>SORT_DESC - ë´ë¦¼ì°¨ìì¼ë¡ ì ë ¬</simpara> + </listitem> + </itemizedlist> + </para> + <para> + ì ë ¬ íí íëê·¸: + <itemizedlist> + <listitem> + <simpara>SORT_REGULAR - íµìì ì¼ë¡ ìì´í ì ë¹êµ</simpara> + </listitem> + <listitem> + <simpara>SORT_NUMERIC - ìì¹ë¡ì ìì´í ì ì ë ¬</simpara> + </listitem> + <listitem> + <simpara>SORT_STRING - 문ìì´ë¡ì ìì´í ì ì ë ¬</simpara> + </listitem> + </itemizedlist> + </para> + <para> + ê°ê°ì ë°°ì´ìë ê°ì íì ì ì ë ¬ íëê·¸ ëê°ê° ì§ì ë ì ìë¤. + ë°°ì´ ë§¤ê°ë³ìì ëª ê¸°ë ì ë ¬ íëê·¸ë ë¨ì§ ê·¸ ë°°ì´ìë§ ì ì©ëë¤ + - ì´ë ìë¡ì´ ë°°ì´ì´ 매ê°ë³ìë¡ ì¤ê¸° ì ì 기본ê°ì¸ SORT_ASCì + SORT_REGULAR ë¡ ë¦¬ì ëë¤. + </para> + <para> + ì±ê³µìì ì°¸ì ë°ííë©°, ì¤í¨ìì ê±°ì§ì ë°ííë¤. + </para> + <para> + <example> + <title>Sorting multiple arrays</title> + <programlisting role="php"> +$ar1 = array ("10", 100, 100, "a"); +$ar2 = array (1, 3, "2", 1); +array_multisort ($ar1, $ar2); + </programlisting> + </example> + </para> + <para> + ì를 ë¤ì´, ì ë ¬ íì ì²ì ë°°ì´ì 10,"a",100,100 ì í¬í¨íë¤. + ëë²ì§¸ ë°°ì´ì 1,1,2,"3" ì í¬í¨íë¤. + 첫ë²ì§¸ ë°°ì´ì ê°ê°ì ìí¸ë¦¬(100 ê³¼ 100)ì ëìëë + ëë²ì§¸ ë°°ì´ì ìí¸ë¦¬ ëí ì ë ¬ëë¤. + The entries in the second array corresponding to the identical + entries in the first array (100 and 100) were sorted as well. + </para> + <para> + <example> + <title>ë¤ì°¨ì ë°°ì´ì ì ë ¬</title> + <programlisting role="php"> +$ar = array (array ("10", 100, 100, "a"), array (1, 3, "2", 1)); +array_multisort ($ar[0], SORT_ASC, SORT_STRING, + $ar[1], SORT_NUMERIC, SORT_DESC); + </programlisting> + </example> + </para> + <para> + ì´ ììì ì ë ¬ í ì²ì ë°°ì´ì 10, 100, 100, "a"(ì´ë 문ìì´ë¡ + ì²ë¦¬ëì´ ì¤ë¦ì°¨ìì¼ë¡ ì ë ¬.), ê·¸ë¦¬ê³ ëë²ì§¸ ë°°ì´ì + 1, 3, "2", 1 (ì«ìë¡ ì²ë¦¬ëì´ ë´ë¦¼ì°¨ìì¼ë¡ ì ë ¬)ì ê°ëë¤. + </para> + </refsect1> + </refentry> + <refentry id="function.array-pad"> + <refnamediv> + <refname>array_pad</refname> + <refpurpose> + 주ì´ì§ ê°ì 길ì´ë§í¼ ë°°ì´ì ì±ì´ë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_pad</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int <parameter>pad_size</parameter> + </paramdef> + <paramdef>mixed <parameter>pad_value</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_pad</function> returns a copy of the + <parameter>pad_value</parameter>ì ê°ì¼ë¡ <parameter>pad_size</parameter> 길ì´ë§í¼ ì±ìì§ <parameter>input</parameter>ë°°ì´ì ë³µì¬ë³¸ì ë°ííë¤. + <parameter>pad_size</parameter> ê° ìì ê°ì´ë©´, ë°°ì´ì ì¤ë¥¸ìª½ì´ ì±ìì§ê³ , ììë¼ë©´, ì¼ìª½ì´ ì±ìì§ë¤. + <parameter>pad_size</parameter> ê°ì´ <parameter>input</parameter> ë°°ì´ì 길ì´ë³´ë¤ ìê±°ë ê°ë¤ë©´, í¨ë©(padding)ì ì¼ì´ëì§ ìëë¤. + </para> + <para> + <example> + <title> + <function>Array_pad</function> ì</title> + <programlisting role="php"> +$input = array (12, 10, 9); + +$result = array_pad ($input, 5, 0); +// ê²°ê³¼ë array (12, 10, 9, 0, 0) ì´ë¤. + +$result = array_pad ($input, -7, -1); +// ê²°ê³¼ë array (-1, -1, -1, -1, 12, 10, 9) ì´ë¤. + +$result = array_pad ($input, 2, "noop"); +// pad ëì§ ìëë¤. + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-pop"> + <refnamediv> + <refname>array_pop</refname> + <refpurpose>ë°°ì´ ëì ìì를 ë½ìë¸ë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_pop</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_pop</function> ì <parameter>array</parameter>ì ë§ì§ë§ ê°ì ë½ì ë´ê³ ê·¸ ê°ì ë°ííë©°, <parameter>array</parameter>ì 길ì´ë¥¼ ìì íëë§í¼ ì¤ì¸ë¤. + </para> + <para> + <example> + <title> + <function>Array_pop</function> ì</title> + <programlisting role="php"> +$stack = array ("orange", "apple", "raspberry"); +$fruit = array_pop ($stack); + </programlisting> + </example> + </para> + <para> + ì´ ì´í, <varname>$stack</varname> ì "orange" ì "apple" ë¨ 2ê°ì ììë§ ê°ì§ë¤: + <varname>$fruit</varname> ë "raspberry" ì ê°ì ê°ëë¤. + </para> + <para> + <function>array_push</function>, + <function>array_shift</function>, ê·¸ë¦¬ê³ + <function>array_unshift</function> ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-push"> + <refnamediv> + <refname>array_push</refname> + <refpurpose> + ë°°ì´ ëì íë í¹ì ê·¸ ì´ìì ìì를 ë£ëë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_push</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_push</function> ë <parameter>array</parameter> ì ì¤íê³¼ ê°ì´ ë¤ë£¨ë©°, <parameter>array</parameter>ì ëì ì ë¬ëì´ì§ ê°ì ì§ì´ ë£ëë¤. + <parameter>array</parameter>ì 길ì´ë ì§ì´ë£ì´ì§ ê°ë¤ì ìë§í¼ ëì´ëë©° ë¤ìê³¼ ê°ì í¨ê³¼ê° ìë¤. + <programlisting role="php"/> + ë°ë³µëë ê°ê°ì <parameter>var</parameter>ì ëí´ + $array[] = $var; + </para> + <para> + ë°°ì´ì ìë¡ ì¶ê°ë ììì ìê° ë°íëë¤. + </para> + <para> + <example> + <title> + <function>Array_push</function> ì</title> + <programlisting role="php"> +$stack = array (1, 2); +array_push ($stack, "+", 3); + </programlisting> + </example> + </para> + <para> + ì´ ììì <varname>$stack</varname>ì 4ê°ì ìì(1,2,"+",3)를 ê°ë ë°°ì´ì´ ëë¤. + </para> + <para> + <function>array_pop</function>, + <function>array_shift</function>, + <function>array_unshift</function>ì 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-rand"> + <refnamediv> + <refname>array_rand</refname> + <refpurpose> + ë°°ì´ìì íë í¹ì ê·¸ ì´ìì ììì ìì를 ê°ì ¸ì¨ë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_rand</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>num_req</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_rand</function>ì ë°°ì´ì ììì¤ ììë¡ íë í¹ì ì¬ë¬ê°ì ìì를 ê°ì ¸ì¬ ë ì ì©íë¤. + <parameter>input</parameter> ë°°ì´ì íìë¡ íê³ , ì í ì¸ìë¡ <parameter>num_req</parameter>ì´ ì¬ ì ìëë°, + ë½ìë´ê³ ì¶ì ì리먼í¸ì ì를 ì§ì í ì ìê³ í¹ë³í ì§ì ëì§ ììì ëì 기본 ê°ì 1ì´ë¤. + </para> + <para> + ë¨ì§ íëì ììë§ ê°ì ¸ì¤ë©´, <function>array_rand</function>ë ìì ììì ëí í¤ë¥¼ ë°ííë©°, ììì ì¬ë¬ ìì를 ê°ì ¸ì¬ ê²½ì° ê°ê°ì ìì ììì ëí í¤ì ë°°ì´ì ë°ííë¤. + ì´ë ê² í¨ì¼ë¡ì ë°°ì´ìì ë¶í° ììë¡ ê° ë¿ë§ ìëë¼ í¤ë¥¼ ê°ì ¸ ì¬ ì ìë¤. + </para> + <para> + ëì ìì±ì(rand number generator)를 ë§ë¤ê¸° ìí´<function>srand</function> í¨ì를 í¸ì¶íëê²ì ìì§ ë§ë¼. + </para> + <para> + <example> + <title> + <function>Array_rand</function> ì</title> + <programlisting role="php"> +srand ((double) microtime() * 10000000); +$input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank"); +$rand_keys = array_rand ($input, 2); +print $input[$rand_keys[0]]."\n"; +print $input[$rand_keys[1]]."\n"; + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.array-reverse"> + <refnamediv> + <refname>array_reverse</refname> + <refpurpose> + ê° ì리먼í¸ë¥¼ ììì¼ë¡ ì ë ¬í ë°°ì´ì ë°ííë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_reverse</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_reverse</function>ë ì ë ¥ì¼ë¡ + <parameter>array</parameter> 를 ê°ì§ë©° ì리먼í¸ë¤ì´ + ììì¼ë¡ ì ë ¬ë ìë¡ì´ ë°°ì´ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_reverse</function> ì</title> + <programlisting role="php"> +$input = array ("php", 4.0, array ("green", "red")); +$result = array_reverse ($input); + </programlisting> + </example> + </para> + <para> + ì´ ìë <varname>$result</varname> ê° <literal>array + (array ("green", "red"), 4.0, "php")</literal>를 ê°ì§ë¤.. + </para> + </refsect1> + </refentry> + <refentry id="function.array-shift"> + <refnamediv> + <refname>array_shift</refname> + <refpurpose> + ë°°ì´ì 맨 ìì ìë ìì를 꺼ë´ê³ ê·¸ ìì를 ìì íë¤ + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>array_shift</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_shift</function> ë <parameter>array</parameter>ì + 첫ë²ì§¸ ê°ì 꺼ë´ê³ ê·¸ êº¼ë¸ ê°ì ë°ííë©°, <parameter>array</parameter>ì + 첫ë²ì§¸ ì리먼í¸ë¥¼ ìì íê³ ë¤ë¥¸ 모ë ì리먼í¸ë¥¼ í칸 ìì¼ë¡ ì´ëìí¨ë¤. + </para> + <para> + <example> + <title> + <function>Array_shift</function> ì</title> + <programlisting role="php"> +$args = array ("-v", "-f"); +$opt = array_shift ($args); + </programlisting> + </example> + </para> + <para> + ì´ë <varname>$args</varname> ê° "-f" ì ì리먼í¸ë¥¼ ê°ê³ , + <varname>$opt</varname>ë "-v"ì ê°ì ê°ëë¤. + </para> + <para> + <function>array_unshift</function>, + <function>array_push</function>, ê·¸ë¦¬ê³ + <function>array_pop</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-slice"> + <refnamediv> + <refname>array_slice</refname> + <refpurpose>ë°°ì´ì ì¼ë¶ë¥¼ ì¶ì¶íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_slice</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter>offset</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>length</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_slice</function> ë ì¼ë ¨ì ì리먼í¸ë¥¼ + <parameter>offset</parameter> and <parameter>length</parameter>ì + 매ê°ë³ìì ë°ë¼ <parameter>array</parameter> ë¡ë¶í° ë°ííë¤. + </para> + <para> + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë©´, ìíì¤ë + <parameter>array</parameter>ì ì«ìì í´ë¹íë ìµì (offset)ìì ë¶í° + ììíë¤. ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + ìíì¤ë <parameter>array</parameter>ì ëììë¶í° ê·¸ ìë§í¼ + ë¨ì´ì§ ê³³ìì ë¶í° ììíë¤. + </para> + <para> + ë§ì½ <parameter>length</parameter>ì´ ì£¼ì´ì§ê³ ìì ê°ì´ë¼ë©´, + ìíì¤ë ê·¸ ìë§í¼ì ì리먼í¸ê° ë ê²ì´ë¤. + ë§ì½ <parameter>length</parameter>ê° ì£¼ì´ì§ê³ ìì ê°ì´ë¼ë©´, + ìíì¤ë ë°°ì´ì ëìì ë¶í° ê·¸ ê°¯ìë§í¼ì ì리먼í¸ê° ë ê²ì´ë¤. + ìëµì´ ëë¤ë©´, ìíì¤ë <parameter>offset</parameter>ììë¶í° + <parameter>array</parameter> ëê¹ì§ì ì리먼í¸ë¥¼ 모ë ê°ì§ê² ëë¤. + </para> + <para> + <example> + <title> + <function>Array_slice</function> ì</title> + <programlisting role="php"> +$input = array ("a", "b", "c", "d", "e"); + +$output = array_slice ($input, 2); // "c", "d", ê·¸ë¦¬ê³ "e" 를 ë°ííë¤. +$output = array_slice ($input, 2, -1); // "c", "d" 를 ë°ííë¤. +$output = array_slice ($input, -2, 1); // "d" 를 ë°ííë¤. +$output = array_slice ($input, 0, 3); // "a", "b", ê·¸ë¦¬ê³ "c" 를 ë°ííë¤. + </programlisting> + </example> + </para> + <para> + <function>array_splice</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-splice"> + <refnamediv> + <refname>array_splice</refname> + <refpurpose> + ë°°ì´ì ì¼ë¶ë¥¼ ìì íê³ , ê·¸ ìì¹ì ë¤ë¥¸ ë´ì©ì ë¼ì ë£ëë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_splice</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + <paramdef>int <parameter>offset</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>length</optional> + </parameter> + </paramdef> + <paramdef>array + <parameter> + <optional>replacement</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_splice</function>ë <parameter>input</parameter> + ë°°ì´ë¡ ë¶í° <parameter>offset</parameter> ì <parameter>length</parameter>ë¡ ì í´ì§ + ì린먼í¸ë¥¼ ìì íê³ , <parameter>replacement</parameter>ë°°ì´ì´ ì ê³µëë¤ë©´ + ì´ë¥¼ ì ê³µë ë°°ì´ì¼ë¦¬ ì리먼í¸ë¡ ëì²´ìí¨ë¤. + </para> + <para> + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + ìì ë¶ë¶ì ììì <parameter>input</parameter> ë°°ì´ì + ì²ì ë¶í° ê·¸ í´ë¹íë ìµì ê¹ì§ì´ë¤. + ë§ì½ <parameter>offset</parameter>ì´ ìì ê°ì´ë¼ë©´, + <parameter>input</parameter> ë°°ì´ì ëìì ë¶í° ìµì ë§í¼ ë¨ì´ì§ + ê³³ìì ë¶í° ììëë¤. + </para> + <para> + ë§ì½ <parameter>length</parameter>ì´ ìëµëë©´, + <parameter>offset</parameter>ììë¶í° ë°°ì´ì ëê¹ì§ì 모ë + ì리먼í¸ë¥¼ ìì íë¤. + ë§ì½ <parameter>length</parameter>ê° ì ìëê³ ìì ê°ì ê°ëë¤ë©´, + ê·¸ ì ë§í¼ì ì리먼í¸ê° ìì ëë¤. + <parameter>length</parameter>ê° ì ìëê³ ìì ê°ì ê°ëë¤ë©´, + ìì ëë ë¶ë¶ì ëì´ ë°°ì´ì ëììë¶í°ì ì«ìê° ëë¤. + í: <parameter>replacement</parameter>ê° ì§ì ëì´ ìì ë, + <parameter>offset</parameter>ììë¶í° ë°°ì´ì ëê¹ì§ì + 모ë ì리먼í¸ë¥¼ ìì íë ¤ë©´, <parameter>length</parameter>ëì + <literal>count($input)</literal>ì ì¬ì©íë¼. + </para> + <para> + <parameter>replacement</parameter> ë°°ì´ì´ ì§ì ëì´ ìì¼ë©´, + ìì ë ì리먼í¸ë ì´ ë°°ì´ì ì리먼í¸ë¡ ëì²´ëë¤. + + If <parameter>replacement</parameter> array is specified, then + the removed elements are replaced with elements from this array. + If <parameter>offset</parameter> and + <parameter>length</parameter> are such that nothing is removed, + then the elements from the <parameter>replacement</parameter> + array are inserted in the place specified by the + <parameter>offset</parameter>. Tip: if the replacement is just + one element it is not necessary to put <literal>array()</literal> + around it, unless the element is an array itself. + </para> + <para> + The following equivalences hold: + <programlisting> +array_push ($input, $x, $y) array_splice ($input, count ($input), 0, + array ($x, $y)) +array_pop ($input) array_splice ($input, -1) +array_shift ($input) array_splice ($input, 0, 1) +array_unshift ($input, $x, $y) array_splice ($input, 0, 0, array ($x, $y)) +$a[$x] = $y array_splice ($input, $x, 1, $y) + </programlisting> + </para> + <para> + Returns the array consisting of removed elements. + </para> + <para> + <example> + <title> + <function>Array_splice</function> examples</title> + <programlisting role="php"> +$input = array ("red", "green", "blue", "yellow"); + +array_splice ($input, 2); // $input is now array ("red", "green") +array_splice ($input, 1, -1); // $input is now array ("red", "yellow") +array_splice ($input, 1, count($input), "orange"); + // $input is now array ("red", "orange") +array_splice ($input, -1, 1, array("black", "maroon")); + // $input is now array ("red", "green", + // "blue", "black", "maroon") + </programlisting> + </example> + </para> + <para> + See also <function>array_slice</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.array-unique"> + <refnamediv> + <refname>array_unique</refname> + <refpurpose>ë°°ì´ë¡ë¶í° ì¤ë³µë ê°ì ì ê±°íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_unique</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_unique</function> ë ì ë ¥ì¼ë¡ + <parameter>array</parameter>를 ì¶ë ¥ì¼ë¡ë ì¤ë³µë ê°ì´ ìë + ë°°ì´ì ë°ííë¤. + í¤ê°ì ë³´ì¡´ë¨ì ì ìíë¼. + </para> + <para> + <example> + <title> + <function>Array_unique</function> ì</title> + <programlisting role="php"> +$input = array ("a" => "green", "red", "b" => "green", "blue", "red"); +$result = array_unique ($input); + </programlisting> + </example> + </para> + <para> + <varname>$result</varname> ë <literal>array ("a" => + "green", "red", "blue");</literal>ì ê°ì ê°ì§ë ê²°ê³¼ê° ëë¤. + </para> + </refsect1> + </refentry> + <refentry id="function.array-unshift"> + <refnamediv> + <refname>array_unshift</refname> + <refpurpose> + ë°°ì´ì 맨 ìì í ê°ë ê·¸ ì´ìì ìì를 첨ê°íë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_unshift</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_unshift</function> ë <parameter>array</parameter> ì + ìì ì ë¬ëì´ì§ ìì를 첨ê°íë¤. + ììì 목ë¡ì ì ì²´ì ì¼ë¡ í리íëëê³ , ê·¸ ê²°ê³¼ í리íëë ììë + ëì¼í ììë¡ ë¨ììê² ëë¤. + <function>Array_unshift</function> prepends passed elements to + the front of the <parameter>array</parameter>. Note that the list + of elements is prepended as a whole, so that the prepended + elements stay in the same order. + </para> + <para> + <parameter>array</parameter> ì ìë¡ì´ ììì ì를 ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_unshift</function> ì</title> + <programlisting role="php"> +$queue = array ("p1", "p3"); +array_unshift ($queue, "p4", "p5", "p6"); + </programlisting> + </example> + </para> + <para> + <varname>$queue</varname> ê° + "p4", "p5", "p6", "p1", and "p3", 5ê°ì ìì를 ê°ë ê²°ê³¼ê° ëë¤. + </para> + <para> + <function>array_shift</function>, + <function>array_push</function>, ê·¸ë¦¬ê³ + <function>array_pop</function>를 ì°¸ê³ íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.array-values"> + <refnamediv> + <refname>array_values</refname> + <refpurpose>ë°°ì´ì 모ë ê°ë¤ì ë°ííë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>array_values</function> + </funcdef> + <paramdef>array <parameter>input</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Array_values</function> ë + <parameter>input</parameter> ë°°ì´ì 모ë ê°ë¤ì ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Array_values</function> ì</title> + <programlisting role="php"> +$array = array ("size" => "XL", "color" => "gold"); +array_values ($array); // returns array ("XL", "gold") + </programlisting> + </example> + </para> + <note> + <para> + ì´ í¨ìë PHP 4 ìì ì¶ê°ëìê³ , ë¤ìì PHP3ììì 구íì´ë¤. + <example> + <title> + PHP 3 ì¬ì©ì를 ìí<function>array_values</function> ì 구í + </title> + <programlisting role="php"> +function array_values ($arr) { + $t = array(); + while (list($k, $v) = each ($arr)) { + $t[] = $v; + return $t; + } +} + </programlisting> + </example> + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.array-walk"> + <refnamediv> + <refname>array_walk</refname> + <refpurpose> + ë°°ì´ì ê°ê°ì ììì í¹ì í¨ì를 ì ì©íì¬ ìííë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>array_walk</function> + </funcdef> + <paramdef>array <parameter>arr</parameter> + </paramdef> + <paramdef>string <parameter>func</parameter> + </paramdef> + <paramdef>mixed <parameter>userdata</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <simpara> + í¨ì <parameter>func</parameter> ì <parameter>arr</parameter>ì + ê°ê°ì ììì ì ì©íë¤. + <parameter>func</parameter> ì ë°°ì´ ê°ì´ 첫ë²ì§¸ ì¸ìë¡, + ë°°ì´ í¤ë¤ ëë²ì§¸ ì¸ìë¡ ì ë¬ëë¤. + <parameter>userdata</parameter>ê° ì£¼ì´ì§ë©´ ì´ë í¨ìì ì¸ë²ì§¸ ì¸ìë¡ + ì ë¬ëë¤. + </simpara> + <simpara> + <parameter>func</parameter> ì´ ëê° í¹ì 3ê° ì´ìì 매ê°ë³ìê° íìíë©´, + <parameter>userdata</parameter> ì ë°ë¼ì + <function>array_walk</function>ì´ <parameter>func</parameter>를 + í¸ì¶í ëë§ë¤ ë§¤ë² ê²½ê³ ê° ë°ìíë¤. + ì´ë° ê²½ê³ ë <function>array_walk</function> ì '@' 기í¸ë¥¼ ë§ë¶ì´ê±°ë + <function>error_reporting</function> 를 ì¬ì©í¨ì¼ë¡ì ìíë ì ìë¤. + </simpara> + <note> + <para> + <parameter>func</parameter>ì´ ì¤ì ê°ì¼ë¡ ëìí íìê° ìë¤ë©´, + <parameter>func</parameter>ì 첫ë²ì§¸ 매ê°ë³ìë 참조ì ìí + ì ë¬ì´ ëì´ì¼ íë¤. + ê·¸ë¬ë©´, ììì ê°í´ì§ 모ë ë³íê° ë°°ì´ ìì²´ì ë°ìëë¤. + </para> + </note> + <note> + <para> + í¤ì userdata 를 <parameter>func</parameter>ì ì ë¬íë ê²ì + 4.0 ìì ì¶ê°ëìë¤. + </para> + <para> + PHP 4 ììë <function>reset</function> ì í¸ì¶ì´ íìì ì¼ë¡ íìíë¤. + ìëíë©´, <function>array_walk</function> ë 기본ì ì¼ë¡ ë°°ì´ì 리ì + ìí¤ì§ ì기 ë문ì´ë¤. + </para> + </note> + <para> + <example> + <title> + <function>Array_walk</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); + +function test_alter (&$item1, $key, $prefix) { + $item1 = "$prefix: $item1"; +} + +function test_print ($item2, $key) { + echo "$key. $item2<br>\n"; +} + +array_walk ($fruits, 'test_print'); +reset ($fruits); +array_walk ($fruits, 'test_alter', 'fruit'); +reset ($fruits); +array_walk ($fruits, 'test_print'); + </programlisting> + </example> + </para> + <simpara> + <function>each</function> ê·¸ë¦¬ê³ <function>list</function>를 ì°¸ê³ íë¼. + </simpara> + </refsect1> + </refentry> + <refentry id="function.arsort"> + <refnamediv> + <refname>arsort</refname> + <refpurpose> + ë°°ì´ì ììì¼ë¡ ì ë ¬íê³ ì¸ë±ì¤ì ìê´ê´ê³ë¥¼ ì ì§íë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>arsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ì´ í¨ìë ë°°ì´ì ì¸ë±ì¤ê° ê·¸ ë°°ì´ì ììì ìê´ê´ê³ë¥¼ ì ì§í´ì¼ íë + ë°°ì´ì ììì¼ë¡ ì ë ¬íë¤. ì´ í¨ìë ì£¼ë¡ ì¤ì ììì ì ë ¬ì´ ì¤ìí + ìê´ë°°ì´ì ì ë ¬í ê²½ì° ì´ì©ëë¤. + <example> + <title> + <function>Arsort</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +arsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key = $val\n"; +} + </programlisting> + </example> + </para> + <para> + ì´ ìë ë¤ìì ì¶ë ¥í ê²ì´ë¤: + </para> + <para> + <informalexample> + <programlisting> +fruits[a] = orange +fruits[d] = lemon +fruits[b] = banana +fruits[c] = apple + </programlisting> + </informalexample> + </para> + <para> + fruits ê° ìíë²³ ë°ëììë¡ ì ë ¬ëê³ , ê°ê°ì ììì ìê´ëë ì¸ë±ì¤ë + ì ì§ëìë¤. + </para> + <para> + ìµì 매ê°ë³ì <parameter>sort_flags</parameter>ë¡ ì ë ¬ë°©ë²ì + ìì í ì ìì¼ë©°, ìì¸í ì ë³´ë <function>sort</function>를 참조íë¼. + </para> + <para> + <function>asort</function>, <function>rsort</function>, + <function>ksort</function>, ê·¸ë¦¬ê³ <function>sort</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.asort"> + <refnamediv> + <refname>asort</refname> + <refpurpose>ë°°ì´ì ì ë ¬íê³ index associationì ì ì§íë¤. </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>asort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ì´ í¨ìë ë°°ì´ì ì¸ë±ì¤ê° ê·¸ ë°°ì´ì ììì ìê´ê´ê³ë¥¼ ì ì§í´ì¼ íë + ë°°ì´ì ì ë ¬íë¤. ì´ í¨ìë ì£¼ë¡ ì¤ì ììì ì ë ¬ì´ ì¤ìí + ìê´ë°°ì´ì ì ë ¬í ê²½ì° ì´ì©ëë¤. + <example> + <title> + <function>Asort</function> ì</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +asort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key = $val\n"; +} + </programlisting> + </example> + </para> + <para> + ì´ ìì ì ê²°ê³¼ë ë¤ìê³¼ ê°ë¤: + </para> + <para> + <informalexample> + <programlisting> +fruits[c] = apple +fruits[b] = banana +fruits[d] = lemon +fruits[a] = orange + </programlisting> + </informalexample> + </para> + <para> + + fruits ê° ìíë²³ ììë¡ ì ë ¬ëê³ , ê°ê°ì ììì ìê´ëë ì¸ë±ì¤ë + ì ì§ëìë¤. + </para> + <para> + ìµì 매ê°ë³ì <parameter>sort_flags</parameter>ë¡ ì ë ¬ë°©ë²ì + ìì í ì ìì¼ë©°, ìì¸í ì ë³´ë <function>sort</function>를 참조íë¼. + </para> + <para> + <function>arsort</function>, <function>rsort</function>, + <function>ksort</function>, ê·¸ë¦¬ê³ <function>sort</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.compact"> + <refnamediv> + <refname>compact</refname> + <refpurpose> + 주ì´ì§ ì¬ë¬ ë³ìì ì´ë¦ê³¼ ê°ì ê°ì§ë ë°°ì´ì ë§ë ë¤. + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>compact</function> + </funcdef> + <paramdef>mixed <parameter>varname</parameter> + </paramdef> + <paramdef>mixed + <parameter> + <optional>...</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Compact</function> ë ë¤ìí ìì 매ê°ë³ì를 ê°ëë¤. + ê°ê° 매ê°ë³ìë ë³ìì ì´ë¦ì í¬í¨íë 문ìì´ì´ ë ìë ìê³ , + ë³ì ì´ë¦ì ë°°ì´ì´ ë ìë ìë¤. + ë°°ì´ì ê·¸ ìì ë³ì ì´ë¦ì ë°°ì´ì í¬í¨í ì ë ìë¤. + <function>compact</function> ë ì´ ë§¤ê°ë³ì를 ì¬ê·ì ì¼ë¡ ë¤ë£¬ë¤. + </para> + <para> + ì´ë° ê°ê°ì ê²½ì°ì, <function>compact</function> ë + 기존 ì¬ë³¼ í ì´ë¸ìì ê·¸ ì´ë¦ì í´ë¹íë ë³ì를 ì°¾ì ì¶ë ¥íë ë°°ì´ì + ì¶ê°í´ì, ë³ì ëª ì´ í¤ê° ëê³ ë³ìì ë´ì©ì´ ê·¸ í¤ì ê°ì´ ëë ë°°ì´ì + ë°ííë¤. + ê°ë¨í ë§í´, <function>extract</function>ì ë°ë ì´ë¤. + ì´ í¨ìë ì¶ê°ë 모ë ë³ì를 ê°ì§ë ë°°ì´ì ë°ííë¤. + </para> + <para> + ì§ì ëì§ ìì 문ìì´ì ë¨ìí ê°ê³¼ëë¤. + </para> + <para> + <example> + <title> + <function>Compact</function> ì</title> + <programlisting role="php"> +$city = "San Francisco"; +$state = "CA"; +$event = "SIGGRAPH"; + +$location_vars = array ("city", "state"); + +$result = compact ("event", "nothing_here", $location_vars); + </programlisting> + <para> + ì½ë ì¤í í, <varname>$result</varname> ë <literal>array ("event" + => "SIGGRAPH", "city" => "San Francisco", "state" => "CA")</literal>ì´ ë ê²ì´ë¤. + </para> + </example> + </para> + <para> + <function>extract</function> 를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.count"> + <refnamediv> + <refname>count</refname> + <refpurpose>ë°°ì´ ë³ìì ìì ê°ì를 구íë¤.</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>count</function> + </funcdef> + <paramdef>mixed <parameter>var</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ë°°ì´ <parameter>var</parameter>ì ììì ê°¯ì를 ë°ííëë°, + <parameter>var</parameter>ë ëê² ë°°ì´ì´ë¤.(ìëíë©´, ê·¸ ìì ë¤ë¥¸ê²ì + íëì í¸ë§ ê°ì§ ê²ì´ê¸° ë문ì´ë¤.) + </para> + <para> + ë°°ì´ì´ ìë ë³ìë¼ë©´ 1ì ë°ííë¤. + </para> + <para> + ë³ìê° ì ì¸ ëì§ ììë¤ë©´ 0ì ë°ííë¤. + <warning> + <para> + <function>Count</function> ë ì ì¸ëì§ ìì ë³ìì ëí´ 0ì ë°ííê² ì§ë§, + ììê° ìë ë°°ì´ë¡ ì´ê¸°íë ë³ìë 0ì ë°ííë¤. + ë³ìê° ì ì¸ëìëì§ë¥¼ ì기 ìí´ <function>isset</function>를 ì¬ì©íë¼. + </para> + </warning> + </para> + <para> + <example> + <title> + <function>Count</function> ì</title> + <programlisting role="php"> +$a[0] = 1; +$a[1] = 3; +$a[2] = 5; +$result = count ($a); +//$result ë 2ê° ìë 3ì´ë¤. ìëíë©´, 3ê°ì í ë¹ë ììê° ì기 ë문ì´ë¤. + +$a[2] = 1; +$a[4] = ""; +$a[6] = 5; +$a[8] = 7; +$a[10] = 11; +$a[12] = ""; +$result = count ($a); +// 4ê°ì í ë¹ë ììê° ìì¼ë¯ë¡ $result ì ê°ì 4 ì´ë¤. + </programlisting> + </example> + </para> + <para> + <function>sizeof</function>, + <function>isset</function>, ê·¸ë¦¬ê³ + <function>is_array</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.current"> + <refnamediv> + <refname>current</refname> + <refpurpose>ë°°ì´ì íì¬ ìì를 ëë ¤ì¤ë¤</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>current</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + ê°ê°ì ë°°ì´ì íì¬ ìì를 ê°ë¦¬í¤ë ë´ë¶í¬ì¸í°ë¥¼ ê°ëë°, + ì´ ë´ë¶ í¬ì¸í°ë ë°°ì´ì ì½ì ëì´ì§ 첫ë²ì§¸ ìììì ì´ê¸°íëë¤. + </para> + <para> + <function>current</function> í¨ìë ë¨ìí ë´ë¶ í¬ì¸í°ì ìí´ + ì§ìëë íì¬ì ìì를 ë°ííë¤. + ì´ í¨ìë í¬ì¸í°ë¥¼ ì´ë í ë°©ë²ì¼ë¡ë ì´ëìí¤ì§ ìëë¤. + ë´ë¶ í¬ì¸í°ê° ìì 목ë¡ì ë²ì를 ëì´ì ê³³ì ì§ìíë©´, + <function>current</function> ë ê±°ì§(false)를 ë°ííë¤. + <warning> + <para> + ë°°ì´ì´ ê°ì§ë ììê° íëë ìë¤ë©´ (0 ì´ê±°ë "", ë¹ë¬¸ìì´) + ì´ í¨ìë ì´ ììë¤ì ëí´ìë ê±°ì§(false)를 ë°ííë¤. + ì´ë문ì ì§ê¸ ì¬ì©ì¤ì¸ <function>current</function> ë°°ì´ìì + ì ë§ ë¦¬ì¤í¸ì ëì ìëì§ ìëë©´ ë¹ ë°°ì´ì¸ì§ë¥¼ 구ë¶í기 ì´ë µë¤. + ë°°ì´ì´ ììê° ìë ë¹ ë°°ì´ì¸ì§ë¥¼ ìë§ê² ê²í í기 ìí´ìë + <function>each</function> í¨ì를 ì¬ì©íë¼. + </para> + </warning> + </para> + <para> + <function>end</function>, <function>next</function>, + <function>prev</function>, ê·¸ë¦¬ê³ <function>reset</function>를 참조íë¼. + </para> + </refsect1> + </refentry> + <refentry id="function.each"> + <refnamediv> + <refname>each</refname> + <refpurpose> + ë°°ì´ë¡ë¶í° ë¤ìììì í¤ì ê° ìì ë°ííë¤. + Return the next key and value pair from an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>each</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <parameter>array</parameter> ë°°ì´ìì ë¤ì key/value ìì ë°ííë¤. + ì´ ìì ë¤ ê°ì ìì를 ê°ì§ ë°°ì´ë¡ ë°íëëë° ì´ ë¤ ê°ì ììì keyë + <emphasis>0</emphasis>, <emphasis>1</emphasis>, + <emphasis>key</emphasis>, ê·¸ë¦¬ê³ <emphasis>value</emphasis> + ì´ë¤. + <emphasis>0</emphasis> ê³¼ <emphasis>key</emphasis> + ììë ê°ê° ë³ìì key ì´ë¦ì ê°ì§ê³ , + <emphasis>1</emphasis> ê³¼ <emphasis>value</emphasis>ë + ê·¸ ê°ì ê°ì§ê³ ìë¤. + </para> + <para> + ë§ì½ ê·¸ ë°°ì´ì í´ë¹íë ë´ë¶ í¬ì¸í°ê° ë°°ì´ì ë²ì를 ì§ëë©´, + <function>each</function>ë ê±°ì§(false)를 ë°ííë¤. + </para> + <para> + <example> + <title> + <function>Each</function> ì</title> + <programlisting role="php"> +$foo = array ("bob", "fred", "jussi", "jouni", "egon", "marliese"); +$bar = each ($foo); + </programlisting> + <para> + <varname>$bar</varname> ë ë¤ìì í¤(key)/ê°(value) ìì ê°ëë¤. + pairs: + <itemizedlist spacing="compact"> + <listitem> + <simpara>0 => 0</simpara> + </listitem> + <listitem> + <simpara>1 => 'bob'</simpara> + </listitem> + <listitem> + <simpara>key => 0</simpara> + </listitem> + <listitem> + <simpara>value => 'bob'</simpara> + </listitem> + </itemizedlist> + <programlisting role="php"> +$foo = array ("Robert" => "Bob", "Seppo" => "Sepi"); +$bar = each ($foo); + </programlisting> + </para> + <para> + <varname>$bar</varname> ë ë¤ìì í¤(key)/ê°(value) ìì ê°ëë¤. + <itemizedlist spacing="compact"> + <listitem> + <simpara>0 => 'Robert'</simpara> + </listitem> + <listitem> + <simpara>1 => 'Bob'</simpara> + </listitem> + <listitem> + <simpara>key => 'Robert'</simpara> + </listitem> + <listitem> + <simpara>value => 'Bob'</simpara> + </listitem> + </itemizedlist> + </para> + </example> + </para> + <para> + <function>Each</function> ë ëì²´ë¡ ë°°ì´ì ê²í í기 ìí´ + <function>list</function> ì í¨ê» ì°ì¸ë¤; ì를 ë¤ë©´ + <varname>$HTTP_POST_VARS</varname>: + <example> + <title> + Traversing <varname>$HTTP_POST_VARS</varname> with + <function>each</function> + </title> + <programlisting role="php"> +echo "Values submitted via POST method:<br>"; +reset ($HTTP_POST_VARS); +while (list ($key, $val) = each ($HTTP_POST_VARS)) { + echo "$key => $val<br>"; +} + </programlisting> + </example> + </para> + <para> + After <function>each</function> has executed, the array cursor + will be left on the next element of the array, or on the last + element if it hits the end of the array. + </para> + <para> + See also <function>key</function>, <function>list</function>, + <function>current</function>, <function>reset</function>, + <function>next</function>, and <function>prev</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.end"> + <refnamediv> + <refname>end</refname> + <refpurpose> + Set the internal pointer of an array to its last element + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>end</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>End</function> advances <parameter>array</parameter>'s + internal pointer to the last element, and returns that element. + </para> + <para> + See also: <function>current</function>, + <function>each</function>, <function>end</function>, + <function>next</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.extract"> + <refnamediv> + <refname>extract</refname> + <refpurpose> + Import variables into the symbol table from an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>extract</function> + </funcdef> + <paramdef>array <parameter>var_array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>extract_type</optional> + </parameter> + </paramdef> + <paramdef>string + <parameter> + <optional>prefix</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function is used to import variables from an array into the + current symbol table. It takes associative array + <parameter>var_array</parameter> and treats keys as variable + names and values as variable values. For each key/value pair it + will create a variable in the current symbol table, subject to + <parameter>extract_type</parameter> and + <parameter>prefix</parameter> parameters. + </para> + <para> + <function>Extract</function> checks for colissions with existing + variables. The way collisions are treated is determined by + <parameter>extract_type</parameter>. It can be one of the + following values: + <variablelist> + <varlistentry> + <term>EXTR_OVERWRITE</term> + <listitem> + <simpara> + If there is a collision, overwrite the existing variable. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_SKIP</term> + <listitem> + <simpara> + If there is a collision, don't overwrite the existing + variable. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_PREFIX_SAME</term> + <listitem> + <simpara>If there is a collision, prefix the new variable with + <parameter>prefix</parameter>. + </simpara> + </listitem> + </varlistentry> + <varlistentry> + <term>EXTR_PREFIX_ALL</term> + <listitem> + <simpara> + Prefix all variables with <parameter>prefix</parameter>. + </simpara> + </listitem> + </varlistentry> + </variablelist> + </para> + <para> + If <parameter>extract_type</parameter> is not specified, it is + assumed to be EXTR_OVERWRITE. + </para> + <para> + Note that <parameter>prefix</parameter> is only required if + <parameter>extract_type</parameter> is EXTR_PREFIX_SAME or + EXTR_PREFIX_ALL. + </para> + <para> + <function>Extract</function> checks each key to see if it + constitues a valid variable name, and if it does only then does + it proceed to import it. + </para> + <para> + A possible use for extract is to import into symbol table + variables contained in an associative array returned by + <function>wddx_deserialize</function>. + </para> + <para> + <example> + <title> + <function>Extract</function> example</title> + <programlisting role="php"> +<?php + +/* Suppose that $var_array is an array returned from + wddx_deserialize */ + +$size = "large"; +$var_array = array ("color" => "blue", + "size" => "medium", + "shape" => "sphere"); +extract ($var_array, EXTR_PREFIX_SAME, "wddx"); + +print "$color, $size, $shape, $wddx_size\n"; + +?> + </programlisting> + </example> + </para> + <para> + The above example will produce: + <programlisting> +blue, large, sphere, medium + </programlisting> + </para> + <para> + The <varname>$size</varname> wasn't overwritten, becaus we + specified EXTR_PREFIX_SAME, which resulted in + <varname>$wddx_size</varname> being created. If EXTR_SKIP was + specified, then $wddx_size wouldn't even have been created. + EXTR_OVERWRITE would have cause <varname>$size</varname> to have + value "medium", and EXTR_PREFIX_ALL would result in new variables + being named <varname>$wddx_color</varname>, + <varname>$wddx_size</varname>, and + <varname>$wddx_shape</varname>. + </para> + <para> + You must use an associative array, a numerically indexed array + will not produce results. + </para> + <para> + See also: <function>compact</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.in-array"> + <refnamediv> + <refname>in_array</refname> + <refpurpose>Return true if a value exists in an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>bool in_array</funcdef> + <paramdef>mixed <parameter>needle</parameter> + </paramdef> + <paramdef>array <parameter>haystack</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Searches <parameter>haystack</parameter> for + <parameter>needle</parameter> and returns true if it is found in + the array, false otherwise. + </para> + <para> + <example> + <title> + <function>In_array</function> example</title> + <programlisting role="php"> +$os = array ("Mac", "NT", "Irix", "Linux"); +if (in_array ("Irix", $os)){ + print "Got Irix"; + } + </programlisting> + </example> + </para> + </refsect1> + </refentry> + <refentry id="function.key"> + <refnamediv> + <refname>key</refname> + <refpurpose>Fetch a key from an associative array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>key</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Key</function> returns the index element of the + current array position. + </para> + <para> + See also <function>current</function> and <function>next</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.krsort"> + <refnamediv> + <refname>krsort</refname> + <refpurpose>Sort an array by key in reverse order</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>krsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Sorts an array by key in reverse order, maintaining key to data + correlations. This is useful mainly for associative arrays. + <example> + <title> + <function>Krsort</function> example</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +krsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[d] = lemon +fruits[c] = apple +fruits[b] = banana +fruits[a] = orange + </programlisting> + </informalexample> + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <simpara> + See also <function>asort</function>, <function>arsort</function>, + <function>ksort</function> + <function>sort</function>, + <function>natsort</function>and <function>rsort</function>. + </simpara> + </refsect1> + </refentry> + <refentry id="function.ksort"> + <refnamediv> + <refname>ksort</refname> + <refpurpose>Sort an array by key</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>ksort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Sorts an array by key, maintaining key to data correlations. This + is useful mainly for associative arrays. + <example> + <title> + <function>Ksort</function> example</title> + <programlisting role="php"> +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); +ksort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[a] = orange +fruits[b] = banana +fruits[c] = apple +fruits[d] = lemon + </programlisting> + </informalexample> + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <simpara> + See also <function>asort</function>, <function>arsort</function>, + <function>sort</function>, <function>natsort</function>, and + <function>rsort</function>. + </simpara> + <note> + <para> + The second parameter was added in PHP 4. + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.list"> + <refnamediv> + <refname>list</refname> + <refpurpose> + Assign variables as if they were an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>list</function> + </funcdef> + <varargs/> + </funcprototype> + </funcsynopsis> + <para> + Like <function>array</function>, this is not really a function, + but a language construct. <function>list</function> is used to + assign a list of variables in one operation. + <example> + <title> + <function>List</function> example</title> + <programlisting role="php"> +<table> + <tr> + <th>Employee name</th> + <th>Salary</th> + </tr> + +<?php + +$result = mysql ($conn, "SELECT id, name, salary FROM employees"); +while (list ($id, $name, $salary) = mysql_fetch_row ($result)) { + print (" <tr>\n". + " <td><a href=\"info.php3?id=$id\">$name</a></td>\n". + " <td>$salary</td>\n". + " </tr>\n"); +} + +?> + +</table> + </programlisting> + </example> + </para> + <para> + See also <function>each</function> and <function>array</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.natsort"> + <refnamediv> + <refname>natsort</refname> + <refpurpose> + Sort an array using a "natural order" algorithm + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>natsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function implements a sort algorithm that orders + alphanumeric strings in the way a human being would. This is + described as a "natural ordering". An example of the difference + between this algorithm and the regular computer string sorting + algorithms (used in <function>sort</function>) can be seen below: + </para> + <para> + <example> + <title> + <function>natsort</function> example</title> + <programlisting role="php"> +$array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); + +sort($array1); +echo "Standard sorting\n"; +print_r($array1); + +natsort($array2); +echo "\nNatural order sorting\n"; +print_r($array2); + </programlisting> + </example> + </para> + <para> + The code above will generate the following output: + </para> + <para> + <informalexample> + <programlisting> +Standard sorting +Array +( + [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 +) + </programlisting> + </informalexample> + For more infomation see: Martin Pool's <ulink url="&url.strnatcmp;">Natural Order String Comparison</ulink> + page. + </para> + <para> + See also <function>natcasesort</function>, + <function>strnatcmp</function> and + <function>strnatcasecmp</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.natcasesort"> + <refnamediv> + <refname>natcasesort</refname> + <refpurpose> + Sort an array using a case insensitive "natural order" algorithm + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>natcasesort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function implements a sort algorithm that orders + alphanumeric strings in the way a human being would. This is + described as a "natural ordering". + </para> + <para> + <function>natcasesort</function> is a case insensitive version of + <function>natsort</function>. See <function>natsort</function> + for an example of the difference between this algorithm and the + regular computer string sorting algorithms. + </para> + <para> + For more infomation see: Martin Pool's <ulink url="&url.strnatcmp;">Natural Order String Comparison</ulink> + page. + </para> + <para> + See also <function>sort</function>, + <function>natsort</function>, + <function>strnatcmp</function> and + <function>strnatcasecmp</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.next"> + <refnamediv> + <refname>next</refname> + <refpurpose> + Advance the internal array pointer of an array + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>next</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the array element in the next place that's pointed by the + internal array pointer, or false if there are no more elements. + </para> + <para> + <function>Next</function> behaves like + <function>current</function>, with one difference. It advances + the internal array pointer one place forward before returning the + 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, <function>next</function> returns false. + <warning> + <para> + 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 + <function>each</function> function. + </para> + </warning> + </para> + <para> + See also: + <function>current</function>, <function>end</function>, + <function>prev</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.pos"> + <refnamediv> + <refname>pos</refname> + <refpurpose>Get the current element from an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>pos</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <simpara> + This is an alias for <function>current</function>. + </simpara> + <para> + See also: + <function>end</function>, <function>next</function>, + <function>prev</function> and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.prev"> + <refnamediv> + <refname>prev</refname> + <refpurpose>Rewind the internal array pointer</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>prev</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the array element in the previous place that's pointed by + the internal array pointer, or false if there are no more + elements. + <warning> + <para> + 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 + <function>each</function> function. + </para> + </warning> + </para> + <para> + <function>Prev</function> behaves just like + <function>next</function>, except it rewinds the internal array + pointer one place instead of advancing it. + </para> + <para> + See also: <function>current</function>, <function>end</function>, + <function>next</function>, and <function>reset</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.range"> + <refnamediv> + <refname>range</refname> + <refpurpose> + Create an array containing a range of integers + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>array <function>range</function> + </funcdef> + <paramdef>int <parameter>low</parameter> + </paramdef> + <paramdef>int <parameter>high</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Range</function> returns an array of integers from + <parameter>low</parameter> to <parameter>high</parameter>, + inclusive. + </para> + <para> + See <function>shuffle</function> for an example of its use. + </para> + </refsect1> + </refentry> + <refentry id="function.reset"> + <refnamediv> + <refname>reset</refname> + <refpurpose> + Set the internal pointer of an array to its first element + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>mixed <function>reset</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + <function>Reset</function> rewinds <parameter>array</parameter>'s + internal pointer to the first element. + </para> + <para> + <function>Reset</function> returns the value of the first array + element. + </para> + <para> + See also: <function>current</function>, + <function>each</function>, <function>next</function>, + and <function>prev</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.rsort"> + <refnamediv> + <refname>rsort</refname> + <refpurpose>Sort an array in reverse order</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>rsort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int + <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array in reverse order (highest to lowest). + <example> + <title> + <function>Rsort</function> example</title> + <programlisting role="php"> +$fruits = array ("lemon", "orange", "banana", "apple"); +rsort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "$key -> $val\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[0] = orange +fruits[1] = lemon +fruits[2] = banana +fruits[3] = apple + </programlisting> + </informalexample> + </para> + <para> + The fruits have been sorted in reverse alphabetical order. + </para> + <para> + You may modify the behavior of the sort using the optional + parameter <parameter>sort_flags</parameter>, for details + see <function>sort</function>. + </para> + <para> + See also: <function>arsort</function>, + <function>asort</function>, <function>ksort</function>, + <function>sort</function>, and <function>usort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.shuffle"> + <refnamediv> + <refname>shuffle</refname> + <refpurpose>Shuffle an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>shuffle</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function shuffles (randomizes the order of the elements in) + an array. You must use <function>srand</function> to seed this + function. + <example> + <title> + <function>Shuffle</function> example</title> + <programlisting role="php"> +$numbers = range (1,20); +srand ((double)microtime()*1000000); +shuffle ($numbers); +while (list (, $number) = each ($numbers)) { + echo "$number "; +} + </programlisting> + </example> + </para> + <para> + See also <function>arsort</function>, <function>asort</function>, + <function>ksort</function>, <function>rsort</function>, + <function>sort</function> and <function>usort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.sizeof"> + <refnamediv> + <refname>sizeof</refname> + <refpurpose>Get the number of elements in an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>int <function>sizeof</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + Returns the number of elements in the array. + </para> + <para> + See also <function>count</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.sort"> + <refnamediv> + <refname>sort</refname> + <refpurpose>Sort an array</refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>sort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>int <parameter> + <optional>sort_flags</optional> + </parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array. Elements will be arranged from + lowest to highest when this function has completed. + <example> + <title> + <function>Sort</function> example</title> + <programlisting role="php"> +<?php + +$fruits = array ("lemon", "orange", "banana", "apple"); +sort ($fruits); +reset ($fruits); +while (list ($key, $val) = each ($fruits)) { + echo "fruits[".$key."] = ".$val; +} + +?> + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +fruits[0] = apple +fruits[1] = banana +fruits[2] = lemon +fruits[3] = orange + </programlisting> + </informalexample> + </para> + <para> + The fruits have been sorted in alphabetical order. + </para> + <para> + The optional second parameter <parameter>sort_flags</parameter> + may be used to modify the sorting behavior using theese valies: + </para> + <para> + Sorting type flags: + <itemizedlist> + <listitem> + <simpara>SORT_REGULAR - compare items normally</simpara> + </listitem> + <listitem> + <simpara>SORT_NUMERIC - compare items numerically</simpara> + </listitem> + <listitem> + <simpara>SORT_STRING - compare items as strings</simpara> + </listitem> + </itemizedlist> + </para> + <para> + See also: <function>arsort</function>, + <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>. + </para> + <note> + <para> + The second parameter was added in PHP 4. + </para> + </note> + </refsect1> + </refentry> + <refentry id="function.uasort"> + <refnamediv> + <refname>uasort</refname> + <refpurpose> + Sort an array with a user-defined comparison function and + maintain index association + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>uasort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>function <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function sorts an array such that array indices maintain + their correlation with the array elements they are associated + with. This is used mainly when sorting associative arrays where + the actual element order is significant. The comparison function + is user-defined. + </para> + <note> + <para> + Please see <function>usort</function> and + <function>uksort</function> for examples of user-defined + comparison functions. + </para> + </note> + <para> + See also: <function>usort</function>, <function>uksort</function>, + <function>sort</function>, <function>asort</function>, + <function>arsort</function>, <function>ksort</function> + and <function>rsort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.uksort"> + <refnamediv> + <refname>uksort</refname> + <refpurpose> + Sort an array by keys using a user-defined comparison function + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>uksort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>function <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function will sort the keys of an array using a + user-supplied comparison function. If the array you wish to sort + needs to be sorted by some non-trivial criteria, you should use + this function. + </para> + <para> + <example> + <title> + <function>Uksort</function> example</title> + <programlisting role="php"> +function cmp ($a, $b) { + if ($a == $b) return 0; + return ($a > $b) ? -1 : 1; +} + +$a = array (4 => "four", 3 => "three", 20 => "twenty", 10 => "ten"); + +uksort ($a, "cmp"); + +while (list ($key, $value) = each ($a)) { + echo "$key: $value\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +20: twenty +10: ten +4: four +3: three + </programlisting> + </informalexample> + </para> + <para> + See also: <function>usort</function>, <function>uasort</function>, + <function>sort</function>, <function>asort</function>, + <function>arsort</function>, <function>ksort</function>, + <function>natsort</function> and <function>rsort</function>. + </para> + </refsect1> + </refentry> + <refentry id="function.usort"> + <refnamediv> + <refname>usort</refname> + <refpurpose> + Sort an array by values using a user-defined comparison function + </refpurpose> + </refnamediv> + <refsect1> + <title>ì¤ëª </title> + <funcsynopsis> + <funcprototype> + <funcdef>void <function>usort</function> + </funcdef> + <paramdef>array <parameter>array</parameter> + </paramdef> + <paramdef>string <parameter>cmp_function</parameter> + </paramdef> + </funcprototype> + </funcsynopsis> + <para> + This function will sort an array by its values using a + user-supplied comparison function. If the array you wish to sort + needs to be sorted by some non-trivial criteria, you should use + this function. + </para> + <para> + The comparison function must return an integer less than, equal + to, or greater than zero if the first argument is considered to + be respectively less than, equal to, or greater than the + second. If two members compare as equal, their order in the + sorted array is undefined. + </para> + <para> + <example> + <title> + <function>Usort</function> example</title> + <programlisting role="php"> +function cmp ($a, $b) { + if ($a == $b) return 0; + return ($a > $b) ? -1 : 1; +} + +$a = array (3, 2, 5, 6, 1); + +usort ($a, "cmp"); + +while (list ($key, $value) = each ($a)) { + echo "$key: $value\n"; +} + </programlisting> + </example> + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +0: 6 +1: 5 +2: 3 +3: 2 +4: 1 + </programlisting> + </informalexample> + </para> + <note> + <para> + Obviously in this trivial case the <function>rsort</function> + function would be more appropriate. + </para> + </note> + <para> + <example> + <title> + <function>Usort</function> example using multi-dimensional array + </title> + <programlisting role="php"> +function cmp ($a, $b) { + return strcmp($a["fruit"],$b["fruit"]); +} + +$fruits[0]["fruit"] = "lemons"; +$fruits[1]["fruit"] = "apples"; +$fruits[2]["fruit"] = "grapes"; + +usort($fruits, "cmp"); + +while (list ($key, $value) = each ($fruits)) { + echo "\$fruits[$key]: " . $value["fruit"] . "\n"; +} + </programlisting> + </example> + </para> + <para> + When sorting a multi-dimensional array, $a and $b contain + references to the first index of the array. + </para> + <para> + This example would display: + </para> + <para> + <informalexample> + <programlisting> +$fruits[0]: apples +$fruits[1]: grapes +$fruits[2]: lemons + </programlisting> + </informalexample> + </para> + <para> + <warning> + <para> + The underlying quicksort function in some C libraries (such as + on Solaris systems) may cause PHP to crash if the comparison + function does not return consistent values. + </para> + </warning> + </para> + <para> + 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> + </refsect1> + </refentry> +</reference> +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:1 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:"../../manual.ced" +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +-->