1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546
|
<?xml version="1.0" encoding="utf-8"?>
<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>
<methodsynopsis>
<type>array</type><methodname>array</methodname>
<methodparam choice="opt"><type>mixed</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_count_values</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_diff</methodname>
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_flip</methodname>
<methodparam><type>array</type><parameter>trans</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_intersect</methodname>
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_keys</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
search_value
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_merge</methodname>
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_merge_recursive</methodname>
<methodparam><type>array</type><parameter>array1</parameter></methodparam>
<methodparam><type>array</type><parameter>array2</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>bool</type><methodname>array_multisort</methodname>
<methodparam><type>array</type><parameter>ar1</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
arg
</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
...
</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_pad</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam><type>int</type><parameter>pad_size</parameter></methodparam>
<methodparam><type>mixed</type><parameter>pad_value</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>array_pop</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>array_push</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>array_rand</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
num_req
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_reverse</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>array_shift</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_slice</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
length
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_splice</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
length
</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>
replacement
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_unique</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>array_unshift</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>array_values</methodname>
<methodparam><type>array</type><parameter>input</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>array_walk</methodname>
<methodparam><type>array</type><parameter>arr</parameter></methodparam>
<methodparam><type>string</type><parameter>func</parameter></methodparam>
<methodparam><type>mixed</type><parameter>userdata</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>arsort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>asort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>compact</methodname>
<methodparam><type>mixed</type><parameter>varname</parameter></methodparam>
<methodparam choice="opt"><type>mixed</type><parameter>
...
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>count</methodname>
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>current</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>each</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>end</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>extract</methodname>
<methodparam><type>array</type><parameter>var_array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
extract_type
</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>
prefix
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>bool</type><methodname>in_array</methodname>
<methodparam><type>mixed</type><parameter>needle</parameter></methodparam>
<methodparam><type>array</type><parameter>haystack</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>key</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>krsort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>ksort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>list</methodname>
<methodparam rep="repeat"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>natsort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>natcasesort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>next</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>pos</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>prev</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>array</type><methodname>range</methodname>
<methodparam><type>int</type><parameter>low</parameter></methodparam>
<methodparam><type>int</type><parameter>high</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>mixed</type><methodname>reset</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>rsort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>shuffle</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>int</type><methodname>sizeof</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>sort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>
sort_flags
</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>uasort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>function</type><parameter>cmp_function</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>uksort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>function</type><parameter>cmp_function</parameter></methodparam>
</methodsynopsis>
<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>
<methodsynopsis>
<type>void</type><methodname>usort</methodname>
<methodparam><type>array</type><parameter>array</parameter></methodparam>
<methodparam><type>string</type><parameter>cmp_function</parameter></methodparam>
</methodsynopsis>
<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
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->
|